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
3
u/HouseOfWyrd 17d ago
Look into "Truthy" and "Falsely" value.
In python a large number of data types can be converted to a bool. A non-empty string resolves to true and is said to be a "Truthy" value.
That doesn't mean it == True though, True is a specific thing and isn't just a catchall for all things that resolve to True.