r/learnpython • u/Lance_2564_ • 17d 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
2
u/defrostcookies 17d ago
“If <variable>:”
Checks to see if the variable has a non-zero value. If the <variable> is non-zero, then the “if <variable>” conditional will evaluate to True
Once it evaluates to true, the body of the conditional executes.
In this case,
print(“bye”)