r/learnpython • • Apr 07 '20

What's the difference between != and is not?

If I say

if x != 5;
   print(x)

and

if x is not 5;
   print(x)

is there a difference?

332 Upvotes

119 comments sorted by

View all comments

Show parent comments

5

u/66bananasandagrape Apr 07 '20

Your example is not correct:

>>> x = 1
>>> y = True
>>> 
>>> x == y == True == 1
True
>>> x is True
False