Subtract boolean from float in python -


anyways when debuging code found statement subtracted boolean float.

then tried following in python console:

>>> 15.0 - true  14.0 >>> 15.0 - false 15.0 

can explain me:

  • http://docs.python.org/3/library/stdtypes.html#boolean-values

    boolean values 2 constant objects false , true. used represent truth values (although other values can considered false or true).

    in numeric contexts (for example when used argument arithmetic operator), behave integers 0 , 1, respectively.

  • not nowadays, can write

    result = numeric_value * a_bool (this 1 used lot, example, in shader languages)

    instead of

    result = numeric_value if a_bool else 0

    or

    result = (value_if_false, value_if_true)[a_bool]

    don't of though.

it's people experience in lower-level languages expect, why take away them? in c, true , false still macros 1 , 0.

before 2.3, there no bool type in python well, when introduced making subclass of int made sure no code broken.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -