Next / Previous / Contents / TCC Help System / NM Tech homepage

20.5. bool(): Convert to Boolean

This function takes any value x and converts it to a Boolean (true or false) value.

For the list of values that are considered True or False, see Section 7.3, “Type bool: Boolean truth values”. Examples:

>>> bool(0)
False
>>> bool(0.0)
False
>>> bool(0L)
False
>>> bool(0j)
False
>>> bool('')
False
>>> bool([])
False
>>> bool(())
False
>>> bool({})
False
>>> bool(None)
False
>>> bool(1)
True
>>> bool(15.9)
True
>>> bool([0])
True
>>> bool((None,))
True
>>> bool({None: False})
True