# string method does not change the value of the original string
Name = ' besttest '
Print (Name.strip ()) # Default minus spaces and line breaks on both sides
Print (name)
Print (' 123 456 '. Strip (' 456 '))
New_name = Name.lstrip () # Remove the left space and line break
new_name1 = Name.rstrip () # Remove the right space and line break
Print (Name.count (' t ')) # Find the number of occurrences of a string
Print (Name.count (' O '))
name = ' Besttest '
Print (Name.capitalize ()) # Capitalize first letter
Print (Name.center, ' * ') # put the string in the middle, with a total length of 50, to fill the whole
Print (Name.find (' t ')) # find T, return the first occurrence of subscript
Print (Name.find (' O ')) # If not present, return-1
Print (Name.index (' t '))
# Print (Name.index (' O ')) # no time to find an error!
Print (Name.upper ()) # lowercase letters to uppercase
Print (Name.lower ()) # Uppercase to lowercase
name = ' A.txt '
Print (Name.endswith (' txt ')) # returns TRUE or False if the string ends with
Print (Name.startswith (' a ')) # returns TRUE or False if the string starts with what
f = ' {name} welcome '
Print (F.format (name= ' Wangsilei ')) # string formatting
f = ' {name} welcome, {age} '
D = {' name ': ' Panda ', ' age ': 18}
Print (F.format_map (d))
name = ' ABCDE '
Print (Name.replace (' abc ', ' 123 ')) # string substitution
Print (' 123456 '. IsDigit ()) # is the number
Print (' abc '. isupper ()) # to determine if all uppercase letters are
Print (' abc '. islower ()) # to determine if all lowercase letters are
Print (' abc123 '. Isalnum ()) # contains numbers or letters (only numbers or alphabetic combinations)
Print (' AbA '. Isalpha ()) # is the English alphabet
# Important methods of string
str1 = ' A, b, C, D, E, F, G '
Print (Str1.split (', '))
Print ((Str1.split ('))) # string split, return a list
Print ((Str1.split (' B ')))
Print ((Str1.split ())) # do not write default space-delimited
Slit = [' A ', ' B ', ' C ', ' d ']
Name = ', '. Join (Slit) # through, link each value inside the list
Print (name)
S2 = ' hhhhhhhhh '
Print (' * '. Join (S2))
D = {' name ': ' Wangsilei ', ' Age ': 18}
Print (' * '. Join (d)) # only valid for key
name = ' ABCDE '
Print (' A ' in name)
Print (' e ' not in name)
python--string