integer - Is there a python built-in function to get 0 for None -
is there built-in function in python following:
def none_safe(int_value): homecoming int_value if int_value not none else 0
assuming possible inputs none , instances of int:
int_value or 0 some apis, such dict.get, have argument can pass default. in case it's value, note or evaluated lazily whereas function argument evaluated eagerly.
other apis, such constructor of collections.defaultdict, take factory build defaults, i.e. have pass lambda: 0 (or int since callable returns 0), avoids eagerness if that's problem, possibility of other falsy elements.
python integer
No comments:
Post a Comment