I am working with code that exhibits the following behavior. Suppose I have a variable d
and I assign it to an integer 9
d = 9
why do the following statements work?
In [95]: if d:
....: print d
....: else:
....: print 'Did not print d!'
....:
9
In [96]:
when d itself is not a Boolean and does not pass the following tests:
In [96]: d is True
Out[96]: False
In [97]: d is False
Out[97]: False
I will appreciate it if someone could explain this to me and point out any misconception that I have. Thank you very much.