Python string operation, python string
Hard to remember
Name = "abcde"
Name2 = abcd \ te
Name. capitalize () // uppercase letters
Name. count ("a") // count the number of
Name. casefold ()
Name. center (10, "-") // output: --------- abcde ---------
Name. encode () // convert to binary
Name. endswith ("e") // determines whether a string ends with e.
Name2.expandtabs (tabsize = 10) // output: abcd e
Name. find ("a") // returns the index of the character found.
Name. format () // format the string
Name. format_map ({"name": "aa", "age": 12 })
Name. isalnum () // determines whether it is an Arabic number. If the character contains a number, true is returned.
Name. isalpha () // determines whether it is a pure English character
Name. isdigit () // determines whether it is an integer.
Name. isdentifier () // identifies a valid identifier (variable name)
Name. islower () // determines whether it is in lowercase.
Name. isspance () // determines whether it is a space.
Name. istitle () // whether the title Is My Name Is an uppercase letter. true Is returned.
Name. isprinttable () // determines whether printing is allowed
Name. isupper () // whether to use uppercase letters
Name. join ("=") // output: = abcde =
",". Join (['1', '2', '3']) // output 1, 2, 3
Name. ljust (50, "*") // output abcde ********* length is not enough 50 left side with * fill
Name. Must ust (50, '*') Same as above to the right
Name. lower () lower case
Name. upper () Capital
Name. lstrip () // remove spaces and line breaks on the left
Name. rstrip () Same as above on the right
Name. strip () // both sides
Name = str. maketrans ("abc", "123 ")
"Abcfer". translate (name) // output: 123fer
Name. replace ("a", "m", 1) // replace a with m to replace only one
Name. rfind ("e") Find the rightmost e return subscript
Name. split ('B') // splits the string into List B by default, which will be removed during split.
Name. splitlines ()
Name. swapcase () // converts uppercase letters to lowercase letters to uppercase letters.
Name. zfill (50) // If the length is not enough, auto-fill the value on the left