To compare strings regardless of case

Asked 1 years ago, Updated 1 years ago, 91 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.