How Python converts string case

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

How Python converts string case
Python string
Python string
Python string manipulation
How python was invented
Str string in Python
How Python parses XML
How to comment python code
How does Python output integers
How does python output backslashes
Python numpy implements rolling case
How to learn python quickly
How to uninstall python plugin
Python interview questions: string concatenation
How Python implements FTP function
How to understand python objects
How to use python tuples
Is python code case sensitive
How does python update packages
Explain how python references package package
Python string three formatted output
How does python perform matrix operations
How does Python list update value
python how to view webpage code
How to use python thread pool
How Python implements the mail function
How does python change the environment
How to write python configuration file
How to wrap in python code
How to save the python program
Python implements string and number splicing
How to omit parentheses in Python
How to install Python 3.8 on CentOS 8
How to install Python 3.8 on Ubuntu 18.04
How to write classes in python
How to filter numbers in python
How does python call java classes
How to read Excel in Python
How to install Python on CentOS 8
How does python import dependency packages
How to solve python dict garbled
How to view errors in python
How does python enter interactive mode
How does Python generate xml files
How to write return in python
The premise of Python string pooling
How Python operates on file directories
How Python implements the timer function
How to view the python module
How to understand variables in Python
How to clear variables in python
How to understand python object-oriented programming
How does python determine prime numbers
Python classic programming questions: string replacement
How to use SQLite in Python