Data Types
Sayth Renshaw
flebber.crue at gmail.com
Wed Sep 21 23:46:48 EDT 2016
> >
> >> Are there any other data types that will give you type(A) or type(B) =
> >> <class 'bool'> besides True and False?
> >
> > No types but any variable or expression containing True or False will be
> > a bool type (or class bool):
>
> "Containing" True or False? Certainly not:
>
> py> type( [1, 2, True] )
> <class 'list'>
> py> type( False or 99 )
> <class 'int'>
>
> Based on your examples, I think you mean any expression *evaluating to* True
> or False will be a bool. Um, yeah, of course it will. Because it evaluates
> to one of the only two bool values, True or False.
>
> > A = 10<20
> > print (type(A)) => <class 'bool'>
>
> That's because the value of A is True.
>
> > print (10<20) => True
> > print (type(10<20)) => <class 'bool'>
>
> 10<20 shouldn't be thought of as some alternative value which is a bool, any
> more than we should think of 1+1 as being a different value to 2.
>
>
What about 0 or 1 they are true and false like no other numbers? what category do they fall in with regards to booleans?
In [6]: 0 == False
Out[6]: True
In [7]: 1 == True
Out[7]: True
In [8]: 2 == True
Out[8]: False
In [9]: 3 == True
Out[9]: False
In [10]: 3 == False
Out[10]: False
Sayth
More information about the Python-list
mailing list