Saturday, August 30, 2025
HomeLanguagesDifference between casefold() and lower() in Python

Difference between casefold() and lower() in Python

In this article, we will learn the differences between casefold() and lower() in Python. The string lower() is an in-built method in Python language. It converts all uppercase letters in a string into lowercase and then returns the string. Whereas casefold() method is an advanced version of lower() method, it converts the uppercase letter to lowercase including some special characters which are not specified in the ASCII table for example ‘ß’ which is a German letter and its lowercase letter is ‘ss’.

Syntax of lower(): string.lower()
Parameters: It does not take any parameter.
Returns: It returns a lowercase string of the given string.

Syntax of casefold():
string.casefold()
Parameters: It does not take any parameter.
Returns: It returns a lowercase string of the given string.

The lower() method in Python

In this example, we have stored a string in variable ‘string1’ which includes uppercase letters, and converted it to lowercase using the lower() method after that we printed that converted string.

Python3




# Define a string
string1 = "GeeksForGeeks"
print(string1)
  
# Store the output of lower() method
# in string2 
string2 = string1.lower()
print(string2)


Output:

GeeksForGeeks
neveropen

The casefold() method in Python

In this example, we have stored a German letter ‘ß’ in string1 and converted it to lowercase using both methods casefold() and lower() and we can see in the output that casefold() convert it to lowercase whereas using lower() the letter is printed as it is after conversion.

Python3




# Define a string
string1 = "ß"
print("Original string")
print(string1)
  
# Store the output of lower() method
# in string2
print("Convert using casefold()")
string2 = string1.casefold()
print(string2)
  
print("Convert using lower()")
string3 = string1.lower()
print(string3)


Output:

Original string
ß
Convert using casefold()
ss
Convert using lower()
ß

Difference between lower() and casefold() in Python

Below are some more differences between the lower() method and casefold() method.

lower() Method

casefold() Method

It converts only ASCII characters to lowercase. It converts both ASCII and non-ASCII characters to lowercase.
It is suitable for only case-insensitive string comparison. It is suitable for both case-sensitive and case-insensitive string comparisons.
It provides high performance than casefold(). It works slower than lower().
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32249 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11792 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11838 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7013 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6701 POSTS0 COMMENTS