Python String Casefold() Method with Example — pythonpip.com

Parvez Alam
1 min readJan 16, 2022

Python String casefold() is a built-in function used to implement caseless string matching.The casefold() method is very similar to the lower() method in the python. It is used for caseless matching striing in python.

Python String casefold()

The python string casefold() method is used to implement caseless string matching.The casefold() string method is identical to the lower() string technique, only it removes any case distinctions from a string. i.e., while comparing, ignore cases.

Syntax

string.casefold()

Python casefold() doesn’t take any parameter, it returns a string converted in the lower case.

Conver String in lowercase in Python

Let’s create a string in lowercase using python casefold() method.

# test.py string = "Hi, I'm PYTHONPIP BLOG" print("Source String:", string) print("Lowercase String: ", string.casefold())

Output:

Source String: Hi, I'm PYTHONPIP BLOG Lowercase String: hi, i'm pythonpip blog

Compare Two strings using casefold()

We can also use casefold() method to compare two strings.

# test.py s1 = "Hi, I'm PYTHONPIP BLOG" s2 = "hi, i'm pythonpip blog" iif(s1.casefold() == s2.casefold()): print("Both the strings are same") else: print("Both the strings are not same")

Output:

Both the strings are same

Originally published at https://www.pythonpip.com on January 16, 2022.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Parvez Alam
Parvez Alam

Written by Parvez Alam

Hey, I am Parvez Alam. A software developer since 2009. I love learning and sharing knowledge. https://www.phpflow.com/

No responses yet

What are your thoughts?