Use of python strings, use of python strings

Source: Internet
Author: User

Use of python strings, use of python strings

I have read some of the most basic python tutorials on the Internet. They are easy to understand, but they still feel quite cool in the process of writing. You should write more and practice the use of strings!

The idea is: Take "#" as the delimiter and take "teacher_id = 123" on the left ([0] indicates the first index position ), then remove the spaces on both sides (using strip (), take "teacher_id" with "=" as the delimiter, and remove the spaces on both sides. The printed result is similar to "teacher_id: 123"

Common string operations are summarized as follows:

① Remove spaces and some special symbols ('#', '|', etc ):

Remove spaces on both sides of the string: str. strip ()

Delete the space at the end of the string: str. lstrip ()

Delete the space on the left of the string: str. rstrip ()

② String segmentation (blank characters by default ):

Str. split ()

③ String SEARCH:

Str. find () # The index location is returned.

④ Calculate the string length:

Len (str)

⑤ String case:

Str. upper () # uppercase letters
Str. lower () # lowercase letters
Str. capitalize () # uppercase letters
Str. istitle () # whether it is an uppercase letter
Str. isupper () # whether the letter is in upper case
Str. islower () # whether all letters are in lower case

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.