To compare strings regardless of case

Asked 2 years ago, Updated 2 years ago, 104 views

What is the best way to compare strings regardless of case?

"hello python!" "HELLO PYTHON!" "Hello PYThON!" I'd like to say that's all the same.

Please tell me the most Python-like chord

python case-insensitive compare

2022-09-22 08:30

1 Answers

Assuming ASCII string The most Python method is to temporarily change the entire string to lowercase and compare it.

string1 = 'Hello'
string2 = 'hello'

if string1.lower() == string2.lower():
    print "same string"
else:
    print "Different String"


2022-09-22 08:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.