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

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.

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Unity point and click movement

Life started late…… But it’s rocking😊

5 Best Resources to get started with Rust Programming in 2020

3 Simple AWS Services for Cloud Reluctant CIOs

Linux series Part-3

Content Provider for sharing ROOM Database using Kotlin

ROOM Component

Introduction to Tilemap in Unity

Let’s set up a Bluetooth Mesh Network (1)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Parvez Alam

Parvez Alam

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

More from Medium

Calculate a Number Factorial in Python — pythonpip.com

Python Functions and Packages:

S2E5 : Data Types

Loops in Python