I am trying to compare two string variables with == and it is not working for some reason. For example this code
print(dictionary[0])
print("A")
print(dictionary[0] == "A")
prints out
A
A
False
I don't understand why it returns False when they are clearly equal.
it works on me
dictionary = {0:"A"}
print(dictionary[0])
print("A")
print(dictionary[0] == "A")
result:
A
A
True
possible reason is the length, maybe it contain space
try to use strip() to remove the space or check the length of a string len(dictionary[0])
print(dictionary[0].strip() == "A")
print len( dictionary[0] )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With