On 09/20/2016 09:03 PM, Cai Gengyang wrote:
So for example for "bool" , it only applies to True/False and nothing else? (2
data types), i.e. :
Not exactly... bool is the data type (or class), True and False are the only two _values_ (not
Besides the bool class, with its two values, there is also the Nonetype class, which has only
one value: None.
But to expand on/rephrase what has already been said: while the bool class/type has only the
two values True/False, in expressions using logical operators (and, or, not...), ANY data type
can be interpreted as a boolean. These are often referred to as truthy and falsey values to
distinguish them from actual boolean True/False values.
I'm sure you've already seen the list, if not you should quickly learn it...
Any numeric (int, float, complex) that is zero is falsey.
Any empty collection (list, string, dictionary...) is falsey.
EVERYTHING else is truthy.
-=- Larry -=-