In Python 3.x, in an if
condition, should I convert an int
into a bool
if I want to do something only when the int
is zero, or is it just sufficient to use the int
as-is?
# Option 1 - convert i to a bool in the if condition
def fun(i)
if bool(i):
# do something
# Option 2 - just use i in the if condition
def fun(i)
if i:
# do something
i = 0
fun(i)
i = int(some_mathematical_operation(i))
fun(i)