All operations strings Python

= name 'My name IS Jack' 
Print (name.capitalize ()) # capitalized 
print (name.count ( 'a') ) # character occurrences 
print (name.center (50, '* ')) # print 50 characters, make up deficiencies * 
Print (name.endswith ( '!')) # whether the '!' What the end of 
print (name.expandtabs ()) # inside the existing TAB converted to spaces width 
print (name. find ( 'name')) # returns the index of the character 
'' ' 
# string sections may 
print (name [name.find (' name '):]) 
output: 
to the #NAME iS Jack 
' '' 

"" "name = 'My name {name} IS and IS My Age Age} {!' 
Print (name.format (name = 'Jack', Age = 28)) 
output: 
! My name Jack IS 28 and IS My Age "" " 
name = 'my name is {name} and my age is {age}!'
print(name.format_map({'name':'jack', 'age': '28'}))
My name Jack and IS # My Age IS 28!  
Print (name.isalnum ()) # whether Arabic numerals False
Print ( '123'.isalnum ()) #True 
Print (name.isalpha ()) if the string is a string of letters # 
print (name.isascii ()) # If character All characters are ASCII string, it returns True, otherwise False. 
print (name.isdecimal ()) # If the string is a decimal string, it returns True, otherwise False. 
print (name.isdigit ()) # If the string is a numeric string, it returns True, otherwise False. 
print (name.isidentifier ()) # If the string is a valid Python identifier, returns True, otherwise False. 
print (name.islower ()) # If the string is lowercase string, it returns True, otherwise False. 
print (name.isnumeric ()) # If the string is a string value, compared True, otherwise False. 
print (name.isprintable ()) # If the string is printable, returns True, otherwise False. linux everything is a file, tty unprintable, drive unprintable 
print (name.isspace ()) # If the string is empty string, returns True, otherwise False. 
print (name.istitle ()) # title case if the string is a string, it returns True, otherwise False.
print (name.isupper ()) # If the string is a string of uppercase and returns True, otherwise False. 
print ( '.'. join ( name)) # connect any number of strings. Method is called a string is inserted between each of the given string. The result is returned as a new string.
# E.g. example: the Join ([ 'ab &', 'PQ', 'RS']) -> 'ab.pq.rs' '.'. 
# Output:. My .name .is {. Name } .and. .age .is .my. {.} Age.! 
Print (name.ljust (50, '*')) # returns the length and width of the left-justified string. Fill the specified character (space by default) 
Print (name.rjust (50, '*')) # Returns the length and width of right-justified String. Fill the specified character (default is a space) 
Print (name.lower ()) # returns converted to lowercase copy of the string. 
print (name.lstrip ()) # Returns a copy of the string to remove the leading spaces. If a given character but not without character, a character in the character is deleted. 
print (name.rstrip ()) # returns the deleted copy of the string trailing spaces. If instead of a given character is not a character, deleting a character in the character 
P = str.maketrans ( 'ABCDEFG', '1234567') 
Print ( 'AI abcdhkklf'.
If only one parameter, then it must be a dictionary mapping Unicode number (integer) or Unicode character to the serial number, string, or None. Then convert the character keys to the serial number. 
If there are two parameters, which must be equal to the length of the string, and the dictionary generated, x each character will be mapped to the same character position in y. 
If a third parameter, which must be a string, which characters are mapped in results None.
'' ' 
Print (name.partition (' IS ')) # given delimiter string divided into three parts. 
'' ' 
This search string delimiters. If a delimiter is found, 
it returns a triplet, which contains the front portion of the separator, i.e., a delimiter 
portion itself, and the following. 
If a delimiter is not found, the original string contains a 3-tuple is returned 
and two empty string. 
'' ' 
# (' My name ',' IS ','} and {My name Age Age {IS}! ') 
Print (name.replace (' n-',' N ',. 1)) {IS #my the Name Age and IS} My name Age} {! 
Print (name.replace ( 'n-', 'N', 2))} #my the name and the name {IS IS My Age Age} {! 
Print (name.replace ( 'A ',' a ',. 3)) #my NAME NAME} {iS iS and My Age Age} {! 
Print (name.rfind (' a ')) # S returns the highest index found substring promoter contained in the S [start: end], the start and end parameter may be omitted 
print (name.rindex ( 'a'
print (name.rpartition ( 'a') ) # given delimiter string divided into three parts. 
'' ' 
Which starts at the end of the search string from the separator. If 
the delimiter is found, it returns a 
separator, the separator itself, and the part behind it. 
If no delimiter is found, triplet contains two empty string is returned 
and the original string. 
'' ' 
Print ('. 1 + 2 + + 4'.rsplit. 3 ( "+")) # [ '. 1', '2', '. 3', '. 4']    
#none (default) according to any spaces It is divided, an empty string and discarded from the results. 
#maxsplit maximum number of divisions. 1 (the default value) indicates no limit 
print ( '1 + 2 \ n + 3 + 4'.splitlines ()) # [' 1 + 2 ',' + 3 + 4 '] to divide by the automatic line feed is different the OS line linux \ n windows \ r transducer 
print ( 'jack kaller'.swapcase ()) # uppercase to lowercase letters, lowercase letters converted to uppercase. 
Print (name.title ()) {#My the Name} And the Name Is Is My Age Age} {! 
# conversion titlecase 
print (name.zfill (50)) # padded with zeros to the left of the numeric string, in order to fill given field width. String is never truncated.

  

Guess you like

Origin www.cnblogs.com/lcxiao/p/11367107.html