py02_06: String common operations

= name "My name IS yeyu" 
Print (name.capitalize ()) # capitalized
print (name.count ( 'y') ) # y the number of
print (name.center (50, '- ')) # content play, the character is not enough - complement
print (name.encode ()) # is converted into binary
print (name.endswith ( 'u') ) # determines what end, returns a boolean
print (name.expandtabs (tabsize = 3)) # tab key to convert the number of spaces
print (name.find ( 'i') ) # lookup value, returns the index

format formatted

 

 

= B "My name IS year Old" 
Print (b.format (name = 'yeyu', year 23 is =))
Print (b.format_map ({ 'name': 'yeyu', 'year': 23 is})) # the transfer value is a dictionary, and the format is variable
print (b.index ( 'na') ) # Gets the index
print (b.isalnum ()) # letters and Arabic numerals
print (b.isalpha ()) # plain English alphabet
print (b.isdecimal ()) # if the decimal
print (b.isdigit ()) # whether integer
print (b.isidentifier ()) # judge is not a valid identifier (identifier: valid variable name)
Print ( b.islower ()) # judgment is not lower case
print (b.isnumeric ()) # is not a digital
print (b.isspace ()) # is not a blank
print (b.istitle ()) # The title is not
print (b.isprintable ()) # whether printing distinguish TTY
Print (b.isupper ()) # is not capitalized

join method, with the specified string formatted again stitching up, and only a list of strings

 

= b "My name IS yeyu" 
Print (b.ljust (50, '*')) # display the contents of the left, not enough * Completion
print (b.rjust (50, '- ')) # the right side of the display, not enough * completion with
print (b.lower ()) # all lowercase
print (b.upper ()) # all capitalized
print (b.lstrip ()) # remove the left side of space, carriage
print (b. rsplit ()) # remove the white spaces and the right
print (b.strip ()) # remove both sides of the white spaces and
print (b.replace ( 'a', '66')) # 66 to replace a
Print (b.rfind ( 'e')) # find the index of the rightmost value
print (b.split ()) # string into a list of fragments, character spacing for the space (see below), the delimiter can be specified: print (b.split (y))

 

print (b.split ()) # string into a list of fragments, character spacing for the space 
print (b.splitlines ()) # line to change by listing fragment into
print (b.startswith ( 'my') ) # my switch is determined to
print (b.translate ( 'abcdef', 123456)) # corresponding to the exchange, the cipher is similar to control
print (b.endswith ( 'yu') ) # Analyzing ending Yu
Print (b.swapcase ()) # invert case
print (b.zfill (50)) # 50 length, not enough supplemental 0

Guess you like

Origin www.cnblogs.com/yeyu1314/p/12381319.html