Learn Python basics, string
1 #-*-coding:utf-8-*-2 #LC3String ="Actions Speak"4 Print(string.capitalize ())#Capitalize first letter5 Print(string.split ())#divides a string into a list, by default it is a space, you can define a delimiter6 7String ="Hello {name} old {age}"8 Print(string.format (name="Chaco", Age=19))#{} output The corresponding string in combination with format9 #Hello Chaco oldTen one Print(string.count ("a"))#number of "a" in the statistics string a Print(string.center (50,"-"))#indicates how long the print string is, not enough to replace it with "-" - Print(string.isdigit ())#whether an integer is interpreted - Print(string.isidentifier ())#determine if it is a valid variable name the - -String ="Actions\t speak" - Print(string.expandtabs (tabsize=30))#indicates the tab interval length + #Actions Speak - +String ="better late than never" a Print(string.find ("Late"))#find the location where the substring appears at #print (string.index ("old")) #输出子字符串的位置 - -String ="Better lbate Than neverb" - - Print("+". Join (["1","2","3"]))#consolidating the list - #1+2+3 in - Print(string.ljust (50,"-"))#align to the left and print the appropriate length, not enough to "-" to #Better late Than never---------------------------- + Print(string.rjust (50,"+")) - #++++++++++++++++++++++++++++better late Than never the * Print(string.lower ())#uppercase to lowercase $ Print(string.upper ())#Lowercase to uppercasePanax Notoginseng - Print(string.lstrip ("B"))#removes the first substring from the leftmost string, and the substring defaults to a space and carriage return the Print(string.rstrip ("B"))#Remove first substring from rightmost, substring default to space and carriage return + aString ="Hello Lvcheng" theTran = Str.maketrans ("ABCDEFG","1234567")#represents a two substring correspondence relationship + Print(string.translate (TRAN))#conversion by substring correspondence in string - $ Print(string.replace ("e","E", 1))#represents replacing a substring in a string with another substring, with a limit of the number of times, by default replacing all $String ="Hello Lvcheng" - Print(string.rfind ("e"))#from left to right, find the location of the leftmost substring - Print(string.splitlines ())#Click the line break list the Print(string.swapcase ())#change uppercase to lowercase, lower case to uppercase - WuyiString ="Hello Lvcheng" the Print(string.title ())#turn a string into a title - #Hello Lvcheng wu Print(string.zfill (40))#set length, not enough to "0" supplement - #000000000000000000000000000Hello Lvcheng about $ Print(string.encode ())#converts a string into a binary - Print(string.endswith ("DS"))#determine what ends with, returns TRUE or Flase - Print(string.isalnum ())#whether to interpret as a string containing only letters and numbers - Print(string.isalpha ())#the interpretation is only for letters, including case a Print(string.islower ())#whether to interpret as full lowercase + Print(string.isprintable ())#determine if you can print, vty and so on are not printable the Print(string.isspace ())#determine if it is a space - Print(string.istitle ())#determine if the title is $ Print(string.isupper ())#determine if all caps are true
Python---data type---string