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

Python basic tutorial

Python flow control

Fonctions en Python

Types de données en Python

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 it.

The syntax of lower() method is:

string.lower()

Parameters of string lower()

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.

Example1: Convert string to lowercase

# Example string
string = "THIS SHOULD BE LOWERCASE!"
print(string.lower())
# String and numbers
# 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!

Example2: How 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 not the same.")

When running the program, the output is:

The strings are the same.

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

Python string methods