"Basic Python Tutorial" chapter 3rd using string reading notes

Source: Internet
Author: User

Chapter III: Using Strings

1. The string formatting operator is a percent percent

2. Only tuples and dictionaries can format more than one value. A list or other sequence is only interpreted as a value .

The 3.in operator can only find a single character in a string.

4. String method:

①find (): The Find method can find a substring in a longer string, which returns the leftmost index where the substring is located, and returns 1if it is not found . This method can also provide a range of starting and ending points (providing a second, third argument), a range containing the first index, but not a second index, which is a convention in Python .

②join (): This method is used to concatenate elements in a sequence (the elements in a sequence must be strings).

③lower (): Turns all letters in a string into lowercase letters .

④replace (): The function of finding and replacing , the first parameter is the substring being looked up, and the second parameter is the replacement string.

⑤split (): The inverse method of the Join method, and if the delimiter argument is not provided, all spaces are used as delimiters.

⑥strip (): remove The spaces on both sides of the string, Lstrip (), and Rstrip () to remove the left and right spaces respectively.

⑦translate (): The same as the function of the Replace method. However, only a single character is processed, and multiple substitutions can be made at the same time .

"Basic Python Tutorial" chapter 3rd using string reading notes

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.