(Mar-11-2019, 12:11 AM)speedskis777 Wrote: Evaluates false, because 10 is not the same as True
This is not a good example,as it's the
bool()
value of 10 that normally in almost all cases is used in conditions with
if statements
and
loops
.
>>> var = 10
>>> bool(var)
True
>>> bool(var) == True
True
# So if test with "if" var is True
>>> if var:
... print('This is True')
...
This is True
Also in first code you use
or
without
if statements
which is not normal.
>>> "/" or "*"
'/'
>>> "Hello" or "*"
'Hello'
>>> "" or "*"
'*'
# Here get a True or False value because use "if"
>>> if "/" or "*":
... print('This is True')
... else:
... print('This is False')
...
This is True
# Both False then is False
>>> if 0 or "":
... print('This is True')
... else:
... print('This is False')
...
This is False
Quiz True or False in this list?
>>> lst = ['a', '', {}, (), 9, 0, [], None, ('hello'), {'a': 99}]
>>> [bool(i) for i in lst]
Output:
[True, False, False, False, True, False, False, False, True, True]