#Readme:#Ne_zha#blogger Address:www.cnblogs.com/ne-zha#Common uses of strings #capitalize the first letter of the stringNe_zha = ('Ne_zha') Ne_zha=ne_zha.capitalize ()Print(Ne_zha)#capitalize the first letter of the stringNe_zha = ('Ne_zha') Ne_zha=ne_zha.count ('_') Print(Ne_zha)#several types of fill character usageNe_zha = ('Ne_zha') Ne_zha=ne_zha.center (30,'@') Print(Ne_zha) Ne_zha=('Ne_zha') Ne_zha=ne_zha.ljust (30,'@') Print(Ne_zha) Ne_zha=('Ne_zha') Ne_zha=ne_zha.rjust (30,'@') Print(Ne_zha) Ne_zha=('Ne_zha') Ne_zha=ne_zha.zfill (30) Print(Ne_zha)#convert to binary codeNe_zha = ('123') Ne_zha=Ne_zha.encode ()Print(Ne_zha)#determine the end of the character falseNe_zha = ('Ne_zha') Ne_zha=ne_zha.endswith ('a') Print(Ne_zha)#determine the subscript of the first characterNe_zha = ('Ne_zhaz') Ne_zha=ne_zha.find ('Z') Print(Ne_zha)#determine the subscript of the last characterNe_zha = ('Ne_zhaz') Ne_zha=ne_zha.rfind ('Z') Print(Ne_zha)#Formatting StringsName = ('My name is {x}') Names=name.format (x='Ne_zha') Print(names) name=('My name is {0}') Names=name.format ('Ne_zha') Print(names)#names =name.format_map () #Alpha-Numeric return TrueNe_zha = ('nezha233') Ne_zha=Ne_zha.isalnum ()Print(Ne_zha)#Pure Letter Returns TrueNe_zha = ('Nezha') Ne_zha=Ne_zha.isalpha ()Print(Ne_zha)#Determining decimal charactersNe_zha = ('2333') Ne_zha=Ne_zha.isdecimal ()Print(Ne_zha)#judging integersNe_zha = ('2333') Ne_zha=ne_zha.isdigit ()Print(Ne_zha)#Judging Legal charactersNe_zha = ('Ne_zha') Ne_zha=Ne_zha.isidentifier ()Print(Ne_zha)#determines whether a string is in plain lowercase lettersNe_zha = ('ne_zha233') Ne_zha=Ne_zha.islower ()Print(Ne_zha)#determine if the string is in plain capital lettersNe_zha = ('ne_zha233') Ne_zha=Ne_zha.isupper ()Print(Ne_zha)#determines whether an integer (? The difference between isnumeric and digit? )Ne_zha = ('233.3') Ne_zha=ne_zha.isnumeric ()Print(Ne_zha)#determine if a pure spaceNe_zha = (' ') Ne_zha=ne_zha.isspace ()Print(Ne_zha)#determine if the title formatNe_zha = ('Ne Zha233') Ne_zha=Ne_zha.istitle ()Print(Ne_zha)#determine if you can printNe_zha = ('ne_zha233') Ne_zha=ne_zha.isprintable ()Print(Ne_zha)#@@ 将 elements in the sequence to generate a new string with the specified character connectionstr =' 'Ne_zha=['2','3','3','3'] Print(Str.join (Ne_zha))#@@ 指定 specified delimiter to slice a stringNe_zha = ('My name is \nne_zha\n!!!') Print(Ne_zha.split ('\ n')) Print(Ne_zha.split ('\ n', 1)) #Convert uppercase letters in a string to lowercaseNe_zha = ('ne_zha233') Ne_zha=Ne_zha.lower ()Print(Ne_zha)#Convert uppercase letters in a string to lowercaseNe_zha = ('ne_zha233') Ne_zha=Ne_zha.upper ()Print(Ne_zha)#Convert a string to the title formatNe_zha = ('ne_zha233') Ne_zha=Ne_zha.title ()Print(Ne_zha)#string Casing InverseNe_zha = ('ne_zha233') Ne_zha=ne_zha.swapcase ()Print(Ne_zha)#@@ 去除 The specified character from the beginning of the string, the default white space characterNe_zha = ('Nne_zha 233\n') Ne_zha=ne_zha.strip ('N') Print(Ne_zha) Ne_zha=('\nne_zha 233\n') Ne_zha=Ne_zha.rstrip ()Print(Ne_zha) Ne_zha=('\nne_zha 233\n') Ne_zha=Ne_zha.lstrip ()Print(Ne_zha)#replacing characters in a stringNe_zha = ('ne_zha233') Ne_zha=ne_zha.replace ('3','6', 1) Print(Ne_zha)
What is the difference between split and spitlines,isnumeric and digit??
Python diary, common string usage