C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Casefold: Newer versions of Python support the casefold method. Similar to lower(), it handles Unicode characters better.
Lower: We can also use the lower method to standardize the casing of strings in our programs.
Python program that tests string equality
value = "CAT"
if value == "cat":
print("A") # Not reached.
if value == "CAT":
print("B")
if str.casefold(value) == "cat":
print("C")
if str.lower(value) == "cat":
print("D")
Output
B
C
D
Python program that uses equals, not equals
location1 = "forest"
location2 = "FOREST".lower()
# These two strings are equal.
if location1 == location2:
print("In forest")
# These two strings are not equal.
if location1 != "desert":
print("Not in desert")
Output
In forest
Not in desert