Saturday, November 16, 2024
Google search engine
HomeLanguagesPython String lower() Method

Python String lower() Method

Python String lower() method converts all uppercase characters in a string into lowercase characters and returns it. In this article, we will cover how lower() is used in a program to convert uppercase to lowercase in Python. Here we will also cover casefold and swapcase function to lower our string.

Syntax of String lower()

Syntax: string.lower()

Parameters: The lower() method doesn’t take any parameters. 

Returns: Returns a lowercase string of the given string

Convert a string to lowercase

String with only alphabetic characters 

Python3




text = 'GeEks FOR geeKS'
 
print("Original String:")
print(text)
 
# lower() function to convert
# string to lower_case
print("\nConverted String:")
print(text.lower())


Output: 

Original String:
GeEks FOR geeKS

Converted string:
Lazyroar for Lazyroar

lower() function to convert string to lower_case

String with Alphanumeric Characters 

Python3




text = 'G3Ek5 F0R gE3K5'
 
print("Original String:")
print(text)
 
# lower() function to convert
# string to lower_case
print("\nConverted String:")
print(text.lower())


Output: 

Original String:
G3Ek5 F0R gE3K5

Converted String:
g3ek5 f0r ge3k5

Comparison of strings using lower() method

One of the common applications of the lower() method is to check if the two strings are the same or not.

Python3




text2 = 'gEeKS fOR GeeKs'
 
# Comparison of strings using
# lower() method
if(text1.lower() == text2.lower()):
    print("Strings are same")
else:
    print("Strings are not same")


Output: 

Strings are same

swapcase() function to convert string to lower_case

Convert uppercase to lowercase in python using swapcase function.

Python3




s = 'GEEKSFORGEEKS'
print(s.swapcase())


Output:

neveropen

casefold() function to convert string to lower_case

Convert uppercase to lowercase in python using casefold function.

Python3




s = 'GEEKSFORGEEKS'
print(s.casefold())


Output:

neveropen

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments