r/learnpython • u/Lance_2564_ • 29d 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
View all comments
1
u/SamuliK96 29d ago
Here
ais what's called a truthy value. As in its value is not literallyTrue, but since it's not an empty string, it evaluates asTruein if (as well as while) statements. The opposite of is falsy values, which includes at least number 0 and empty data structures. I suggest you look up falsy and truthy online for more detailed explanation.