Checking a value inside the same type in python

a = 0 if a == False: print a 

in php I can say:

 $a = 0; if $a === false { echo $a; } 

The triple === in php checks the value inside the same type, thereby making the integer 0 not read as a boolean value False How can I do this in python? I would like to distinguish 0 from an integer and False boolean in a simple if statement.

+4
source share
2 answers

In this case, use is . This is an identical operator, the same as === in PHP.

 >>> a = 0 >>> if a is False: ... print a ... >>> 
+5
source

type() will give you the type of the object. But if you are worried about the difference between 0 and False , then perhaps you should use None instead.

0
source

All Articles