Representation of string strings in Python
The string has a total of 4 representation methods
- Use a pair of single quotes to denote
' Python '
- Use a pair of double quotation marks to denote
" Python "
- Use a pair of three single quotes or a pair of three double quotation marks to represent multiple lines of string
"" "
- Use () to nest strings with quotation marks
' here is a double quote (") ' " here's a single quote (') "
Use of strings
- Index operation--Returns a single character in a string
" python " [0]
- Slice operation--returns a substring from M to n (n) index not included
" Python " [1:3]
- Advanced Slice operation-Returns a slice of k from M to N, with the M default beginning, and n the default value ending
" 0 1,234,567,890 " " 1357 " " 0 1,234,567,890 " " 9,876,543,220 "
The operator of the string
Connect two strings x and Y
Copy n times x string
Returns True if X is a substring of s, otherwise false.
string-related functions
Returns the length of the string x
Returns the string form of any type X
16 binary form of integer x
8 binary form of integer x
X is a Unicode encoding that returns its corresponding characters.
X is the corresponding character and returns its corresponding Unicode encoding.
Common methods of strings
Returns a copy of the string, with all characters lowercase.
Returns a copy of the string, with all characters capitalized.
Returns a list of sections in Str that are separated by Sep.
Returns the number of times a sub substring appears in Str.
Returns a copy of the string str, and all old substrings are replaced with new.
- Str.center (Width,[,fillchar])
The string is centered on width widths. Fill word defaults think English space.
Remove all characters from the chars string from the left and right sides of Str.
Adds a str after each character in the string ITER except for the last character. Commonly used to divide words using.
Use of strings in Python