Often I am checking if a number variable number
has a value with if number
but sometimes the number could be zero. So I solve this by if number or number == 0
.
Can I do this in a smarter way? I think it's a bit ugly to check if value is zero separately.
Edit
I think I could just check if the value is a number with
def is_number(s):
try:
int(s)
return True
except ValueError:
return False
but then I will still need to check with if number and is_number(number)
.