1 == True but 1 is not True: The Truth About True

Asha AsvathamanAsha Asvathaman
1 min read

Today I was playing around with Python and stumbled on some truths (pun intended πŸ˜„). I realized I was a bit fuzzy on when to use == vs is. So let's explore this a bit!

You've probably seen this before:

x = True
print(x is True)  # βœ… True

x = 1 == 1
print(x is True)  # βœ… Still True!

Why? Because 1 == 1 evaluates to the boolean True, so x is actually the True object.

Integers are truthy too:

print(1 == True)  # βœ… True!

So far so good!

But now try this:

x = int(1)
print(x is True)  # ❌ False!

Wait β€” what?! Didn’t we just show that 1 == True? And now x = int(1), but this is False?

That's because, even though 1 is truthy, it’s not the same object as True. But it does have the same value as True.

To recap :

  • 1 == True βœ… (same value)

  • 1 is True ❌ (not the same object)

  • type(1) != type(True) β†’ int vs bool

Thus:

  • Use == for value checks

  • Use is for identity checks (like None, True, or False)

0
Subscribe to my newsletter

Read articles from Asha Asvathaman directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Asha Asvathaman
Asha Asvathaman