Name ="My \tname is {name} and I am {year} old"Print(name.capitalize ())#capitalize the first letter of a variable or string in EnglishPrint(name.casefold ())#Convert a variable or string to lowercase in EnglishPrint(name.center (50,"-"))#put the variable in the center, with a total of 50 "-" connections on both sidesPrint(name.count ("m"))#Print the number of occurrences of this valuePrint("chinese". Encode ('gb2312'))#Decodes the string str with GB2312 encoding to obtain the String type Object u1
Print(name.endswith ("Eng"))#determines whether the end is the value Print(name.expandtabs (tabsize=30))#\ t converts to a space Print(name.find ("name"))#Print the subscript position of ' name ' Print(name[name.find ("name")]) Print(name.format (name="Peng", Year=26))#Assign Value Print(name.format_map ({'name':'Peng',' year': 12}))#Dictionary Print(name.index ("name"))#Print the subscript position of ' name ' Print("1d2s". isalnum ())#determines whether English characters + Arabic numerals (not in order or mixed, not including special Characters) Print("Ooii". Isalpha ())#determines whether it is a plain English character, including case Print("6". Isdecimal ())Print("name". Isidentifier ())#determine if it is a valid identifier (variable Name) Print(" the". IsDigit ())#determines whether an integer Print("OPPP". Islower ())#determine if the lowercase letter Print("888". IsNumeric ())#determines whether an integer Print("PPPP". isprintable ())#determine if a file can print TTY File,diver file Print(" ". isspace ())#determine if it is a space Print("My Name". Istitle ())#determine if the first letter of each letter is uppercase Print("Namt". Isupper ())#to determine whether English characters are all uppercase Print('+'. Join (['1','2','3']))#Connection Variables Print(name.ljust (50,'*'))#variable or end of string to complement length Print(name.rjust (50,'-'))#variable or string at the beginning of the complement length Print(name.upper ())#variable or string is capitalized Print(name.lower ())#variable or string is lowercase Print('\npeng'. Lstrip ())#Remove a space or carriage return to the left of a variable or string Print('peng\n'. Rstrip ())#Remove the space or carriage return to the right of a variable or string Print('\npeng\n'. Strip ())#Remove spaces or carriage returns at both ends of a variable or stringp = Str.maketrans ("Abcdefghi",'123456789')#turn the preceding string into the corresponding value Print("Penghx". Translate (p))#the string corresponds to the method of P Print("Peng Peng". replace ('P','P', 1))#replace, number is the number of replacements Print("Peng Peng". RFind ('P'))#Locate the last position of the character in a variable or string Print(name.split ())#separated by a variable or (") in a string as a list Print("1+2\n+3+4". Splitlines ())#separated by line breaks as a list (automatically identify line breaks for different Systems) Print("Peng Peng". Swapcase ())#variable or string English character uppercase to lowercase, lowercase to uppercase Print(name.title ())#variable or string the first letter of the English word becomes uppercase Print(name.zfill (50))#variable or string length not enough 50, with 0 padding at the beginning
⑨python String Common operations