Three ways to replace in Python

Source: Internet
Author: User

Strip () replace () Re.sub ()

1.replace () is a python built-in function, character type. replace (old,new)

s1= "Hello 2017"

S1.replace ("2017", "2018")

2. Strip () deletes the specified character, but only the character at the first place. If there is a space in the first place, you cannot delete the characters, remove the whitespace character without any parameters (including ' \ n ', ' \ R ', ' \ t ', '), but delete only the beginning and end of the string, and you cannot delete the middle

s1= "oghd khnn \ r \ n \ t"

S1.strip ()

S1.strip ("NN")

The. Strip () function also has two versions: Lstrip () and Rstrip (), respectively, to remove the "other characters" from the beginning.

Three ways to replace in Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.