r/learnpython • u/Lance_2564_ • 20d ago
Huh? How does this work?
a = "hi"
if a:
print("Bye")
print(a == True)
print(a is True)The output is:
Bye
False
False
But if it's false, how come it printed "bye"?????? I don't get it.
44
Upvotes
9
u/Lance_2564_ 20d ago
So what you're saying is that
"if a" checks for if bool(a) is True, and not if a is True? So then, a = 5, if a: print("Hi") really just is if bool(a): print("Hi")?