Yes, bool
. It's not exactly the same -- '0'
is True
, but None
, False
, []
, 0
, 0.0
, and ""
are all False
.
bool
is used implicitly when you evaluate an object in a condition like an if
or while
statement, conditional expression, or with a boolean operator.
If you wanted to handle strings containing numbers as PHP does, you could do something like:
def empty(value):
try:
value = float(value)
except ValueError:
pass
return bool(value)