In Python, variables have truthy values based on their content. For example:
>>> def a(x):
... if x:
... print (True)
...
>>> a('')
>>> a(0)
>>> a('a')
True
>>>
>>> a([])
>>> a([1])
True
>>> a([None])
True
>>> a([0])
True
>>> print (1==1)
True
>>> print (1<5)
True
>>> print (5<1)
False
True
False
print (not not a)
Use the builtin bool
type.
print(bool(a))
Some examples from the REPL:
>>> print(bool(''))
False
>>> print(bool('a'))
True
>>> print(bool([]))
False