Sometimes I want to check the logical value of an expression, so I type it in Python (or IPython) and get the result:
>>> a==3
True
But in other cases it doesn't work that way (here string is None):
>>> string
>>>
So I check the logical value like this:
>>> if string: print('True')
...
>>>
Is there a shorter way for checking the logical value of an expression? Any function that returns True or False the same way it will be evaluated in an if-condition?
Yes, it's the
bool()
function: