Python String casefold()

Python String casefold() method

Python String casefold() method is used to convert all of the characters in the given string to lowercase.

Consider that given string is in x.

x = "HELLO World"

Then the return value of x.casefold() is

"hello world"
Python String casefold()

Syntax of casefold() method

The syntax of String casefold() method in Python is given below.

string.casefold()

The casefold() method takes no parameters.

casefold() method returns a new string created using the given string and converting all the characters in the string to lowercase.

The original string is not modified in value, and remains the same.

Examples

1. Casefold given Python string to lowercase

In the following program, we take a string in variable x, and convert the string to lowercase using String casefold() method. We shall store the casefold() returned value in result variable. And then print both the original string x and casefold string result.

Python Program

x = "HELLO World"
result = x.casefold()
print(f"Given string   : {x}")
print(f"Result string  : {result}")
Run Code Copy

Output

Given string   : HELLO World
Result string  : hello world

Summary

In this tutorial of Python String Methods, we learned about String casefold() method, its syntax, and examples.

Related Tutorials

Code copied to clipboard successfully 👍