String, can be any type of string, such as name, a sentence and so on
' Sriba ' 'Welcome to my blog. '
String also has a lot of built-in methods to manipulate strings, the common method is as follows, the following comment with whether or not, the return is a Boolean value:
name = ' my \ t name ' is {Name},age are {age}. '
Print (Name.capitalize ()) # Uppercase
Print (Name.center (50, '-')) # 50--Put the name in the middle
Print (Name.endswith (' U ')) # Does it end with X
Print (Name.expandtabs (30)) # Number of times to fill \ t
Print (Name.find (' n ')) # Find the index of the string
Print (Name.format (name= ' Niuniu ', age=18)) # This is the format string, and then the first section of the blog has been written
Print (Name.format_map ({' name ': ' Niuniu ', ' age ': 19}) # This is also a formatted string, followed by a dictionary, the dictionary will be written in the back
Print (' abA123 '. Isalnum ()) # contains numbers and letters
Print (' AbA '. Isalpha ()) # is the English alphabet
Print (' 122 '. IsDigit ()) # is the number
Print (' AA '. Isidentifier ()) # is a valid variable name
Print (' AA '. Islower ()) # Whether it is a lowercase letter
Print (' AA '. Isupper ()) # is an uppercase letter
Print (' LoadRunner book '. Istitle ()) # is not a title that determines whether the first letter is capitalized
Print (' + '. Join ([' hehe ', ' haha ', ' ee ')) # stitching strings
Print (Name.lower ()) # turns lowercase
Print (Name.upper ()) # becomes uppercase
Print (' \nmysql \ n '. Lstrip ()) # By default, the left space and line breaks are removed
Print (' \nmysql \ n '. Rstrip ()) # Default to remove the right space and line breaks
Print (' \nmysql \ n '. Strip ()) # Default to remove both sides of the space and line wrapping
p = Str.maketrans (' ABCDEFG ', ' 1234567 ') # precedes the string and follows the string to do the mapping
Print (' CC AE GG '. Translate (P)) # outputs a mapped string following the Maketrans above
# The following is the inverse solution
new_p = Str.maketrans (' 1234567 ', ' ABCDEFG ')
Print (' CC AE GG '. Translate (new_p))
Print (' MySQL is db. '. Replace (' MySQL ', ' Oracle ', 1) ' # replacement string
Print (' MySQL is a db '. RFind (' is ') # returns the subscript of the rightmost character
Print (' 1+2+3+4 '. Split (' + ')) # cut string, return a list
Print (' 1+2+3\n1+2+3+4 '. Splitlines ()) # Split by line break
Print (' Abcdef '. Swapcase ()) # case reversal
Python3 Learning Notes-string and string manipulation