r/learnpython • • Oct 19 '26

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

38 comments sorted by

View all comments

1

u/__peg_parser__ Oct 22 '26

Using operator module, if a: would correspond to operator.truth(a), a == True to operator.eq(a, True), and a is True to operator.is_(a, True).