I am trying to compare two string and ignore case- sensitive but i don't want to use .lower() or .upper(). Is there another way of doing this?
Asked
Active
Viewed 269 times
-1
-
3The big question is... why? – Tomerikoo Feb 06 '20 at 13:02
-
It seems to me to be unreasonable to do lower twice so i'd wanted to know if there is another way – Doron Shevach Feb 06 '20 at 13:18
1 Answers
1
example1 = "hello"
example2 = "HeLlo"
if example1.casefold()==example2.casefold():
#do something
This will work without needing upper()
or lower()
. Might not work for non-ASCII characters.

Ahmet
- 434
- 4
- 13
-
-
@Sayse Yes this is assuming ASCII. Does `.lower()` and `.upper()` work well for non-ASCII characters? – Ahmet Feb 06 '20 at 13:04
-
2