Thursday, February 27, 2014

Booleans in Python

I firmly believe that a boolean value should be represented by 0 and 1 - yesterday I have wasted 1 hour because in Ruby you say "True" but in YAML it's "true" (morons the Puppet founding fathers who chose Ruby).
How does it work in Python?
value='1'
booleanValue = (value == '1')
print booleanValue
1

value='0'
booleanValue = (value == '1')
print booleanValue
0

BUT:
value=1
if value:
   print "bla"
bla

value=0
if value:
   print "bla"
bla

So there you are, you can make out the rule to convert 0 and 1 into a boolean.

No comments: