I have two questions.
print (float == True) #prints False
print bool(float) #prints True
bool(), are different.
== is for equality testing, whereas
bool() returns the result of truth value testing for the object passed to it as parameter.
According to documentation of
Return a Boolean value, i.e. one of True or False. x is converted using the standard truth testing procedure. If x is false or omitted, this returns False; otherwise it returns True.
The standard truth testing procedure can be found in the documentation -
Any object can be tested for truth value, for use in an if or while condition or as operand of the Boolean operations below. The following values are considered false:
zero of any numeric type, for example,
any empty sequence, for example,
any empty mapping, for example,
instances of user-defined classes, if the class defines a
__len__()method, when that method returns the integer zero or bool value False.
All other values are considered
True— so objects of many types are always true.
When you do
bool(float), you are checking the truth value for
float, which is True.
But when you do
float == True, you are doing equality (please note this is not truth value testing, it is equality). In this case
True are not equal so that results in