jeudi 21 avril 2016

How differentiate 0 from False In python [duplicate]

This question already has an answer here:

I'm trying to configure the following if else :

Basically 0 is equals to False in Python...

I would like to understand why this happens and how I can workaround in this case :

x=0

if x==False:
   print "x == False" #always prints this line
elif x == 0:
   print "x == 0"

Appreciate the help:

EDIT:

already tried x = int(0)

Aucun commentaire:

Enregistrer un commentaire