I feel very confused about some code like this[not written by me]:
version = any(func1(), func2()) # wrong, should be any([func1(), func2()])
def func1():
if something:
return 1
else:
return None
def func2():
if something:
return 2
else:
return 3
version
must be a num. when [func1(), func2()]
is [1, None]
, should return 1, when is [None, 2]
, should return 2, when [1, 2]
, should return 1.
so I think it's wrong to use any()
in this code, because any()
just return True
or False
. If I rewirte this logic using another way, I can not find a graceful way as a pythoner.
I want to know whether any()
can achieve the logic, if not, how to achieve it gracefully?