Python built-in object (2) String object

Source: Internet
Author: User

The most important thing is that the string in python is an ordered character set (immutable sequence ).

1. Python has no characters and only a single character string.

2. The character string cannot be directly modified at a certain position.

3. Important operations:

S1 + S2 merge

S1 * 3 already exists

S1 [I] Index

S1 [I: J] Fragment

Len (S1) Length

For X in S1 Iteration

'M' in S1 member relationship

4. The functions of single quotes and double quotation marks are the same. Each character can be enclosed by a single quotation mark without the need to escape the character with a backslash.

5. The index is consistent with the character array in C and supports negative offset. For example, s [-2] is the second character from the right.

6. Fragment s [I: J] is the segment from I to J-1 in the S string. (I is not written as the upper bound, J is not written as the lower bound)

7. Modify characters at a certain position in a string by means of indexing, slicing, and merging.

8. String formatting is similar to printf in C.

9. reference the standard string module import string

10. Convert string. Upper (s) to uppercase

String. Find (S, "mm") returns the first character position of the indexed substring

String. atoi ("42") string to a number

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.