1. String Representation
A string consisting of single or double quotation marks.
"ABC "\
'Def'
Represents a string, while "ABC" + "def" are two strings connected together, the two are different.
"Can be any long string in the middle
Ii. String operations
1. case-insensitive Conversion
S. capitalize () # string S: uppercase letters
S. Lower () # lowercase for all
S. Upper () # convert all to uppercase
S. swapcase () # case-insensitive swap
Len (s) # obtain the string size
2. Search for substrings
S. Find (substring, [start [, end]), return index value, cannot find, return-1
S. rfind (substring, [start [, end]) Reverse Lookup
S. Index (substring, [start [, end]) is similar to find (). If substring cannot be found,
Valueerror exception
S. rindex (substring, [start [, end]) Reverse Lookup
S. Count (substring, [start [, end]) returns the number of times the substring is found.
3. format the string
Usage: S % <tuple> tuple indicates a parameter list. Each value in the tuple is represented by a string, and the format represented is determined by S.
S. Ljust (width) is left aligned. If width is greater than Len (s), spaces are added. Otherwise, return S.
S. Align ust (width) right alignment
S. Center (width) Center
S. lstrip () removes the white space on the left
S. rstrip () removes the white space on the right
S. lstrip () removes spaces on both sides
4. String merging and Decomposition
Merge: S. Join (words)
Words is a tuple or list containing strings. Join concatenates strings in words into a string using the separator "S.
Example: >>> "+". Join (["Hello", "my", "friedn"])
'Hello + my + friedn'
Decomposition: S. Split (words)
Words is a string that represents a separator. The split operation is opposite to the join operation. Splits s into a list.
Example: >>> "Hello my fried". Split ("")
['Hello', 'my', 'fried']