The string methods in Python were slowly added from python1.6 to 2.0, and they were also added to Jython. These methods implement most of the methods of the string module. The following table lists the methods currently supported by strings. All methods include support for Unicode, and some are even dedicated to Unicode.
For example: s is a string variable
Method of judging string
s.isalnum() #All characters are numbers or letters
s.isalpha() #All characters are letters
s.isdigit() #All characters are numbers
s.islower() #All characters are lowercase
s.isupper() #All characters are uppercase
s.istitle() #All words are capitalized, like titles
s.isspace() #All characters are blank characters,\t、\n
Case conversion method
s.upper() #Convert all lowercase letters to uppercase letters
s.lower() #Convert uppercase letters in all characters to lowercase letters
s.capitalize() #Convert the first letter to uppercase and the rest to lowercase
s.title() #Convert the first letter of each word to uppercase and the rest to lowercase
Content expansion:
In Python, in order to facilitate the case conversion of letters in a string, string variables provide three methods, namely title(), lower() and upper().
Python title() method
The title() method is used to convert the first letter of each word in the string to uppercase and all other letters to lowercase. After the conversion is completed, this method will return the converted string. If there are no characters to be converted in the string, this method will return the string intact.
Python lower() method
The lower() method is used to convert all uppercase letters in a string to lowercase letters. After the conversion is completed, the method will return the newly obtained string. If the string is originally all lowercase letters, this method will return the original string.
Python upper() method
The function of upper() is exactly the opposite of the lower() method. It is used to convert all lowercase letters in the string to uppercase letters. The return method is the same as the above two methods, that is, if the conversion is successful, it returns a new string; Otherwise, the original string is returned.
This is the end of this article on how Python converts string case. For more relevant Python conversion string case code content, please search ZaLou.Cn’s previous articles or continue to browse the following related articles. Hope you will get more Support ZaLou.Cn!
Recommended Posts