def get(count=None):
if count >= 1:
a = count - 1
else:
a = 0
return a
Everything is in the title.. Just for sport.
Thank you
def get(count=None):
if count >= 1:
a = count - 1
else:
a = 0
return a
Everything is in the title.. Just for sport.
Thank you
You mean using a ternary operator?
a = count - 1 if count >= 1 else 0
Your code will fail if count
is None
because you can't compare nonetypes to integers. But my answer is how you would write this conditional statement in a "better" way.
Thus - I would write the function like this (Thanks @poke for the max
idea.):
def get(count=None):
return max(count-1, 0) if isinstance(count, int) else 0