English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python basic tutorial

Python flow control

Python Functions

Python Data Types

Python file operations

Python objects and classes

Python date and time

Advanced knowledge of Python

Python reference manual

Python string lower() usage and example

Python string methods

The lower() method of the string converts all uppercase letters in the string to lowercase and returns them.

The syntax of the lower() method is:

string.lower()

String lower() parameter

The lower() method does not take any parameters.

Return value from string lower()

The lower() method returns the lowercase string from the given string. It converts all uppercase letters to lowercase.

If there are no uppercase letters, return the original string.

Example1Convert the string to lowercase

# Example string
string = "THIS SHOULD BE LOWERCASE!"
print(string.lower())
# String and number
# All letters are lowercase
string = "Th!s Sh0uLd B3 L0w3rCas3!"
print(string.lower())

When running the program, the output is:

this should be lowercase!
th!s sh0uld b3 l0w3rcas3!

Example2How to use lower() in the program?

# First string
firstString = "PYTHON IS AWESOME!"
# Second string
secondString = "PyThOn Is AwEsOmE!"
if(firstString.lower() == secondString.lower()):
    print("The strings are the same.")
else:
    print("The strings are different.")

When running the program, the output is:

The strings are the same.

Note:If you want to convert it to an uppercase string, please useupper()You can also useswapcase()Swap lowercase and uppercase letters.

Python string methods