DEV Community

Discussion on: Python 'is' vs '=='

Collapse
 
zenulabidin profile image
Ali Sherief

If you try to compare a variable with a literal using is or is not you will get a syntax warning like this:

>>> x=1
>>> x is 0
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
False
>>> x is not 0
<stdin>:1: SyntaxWarning: "is not" with a literal. Did you mean "!="?
True