Like this,assume I need use some library function(I can not change them),it return a value or None, I want use the returned value and pass it to another function.
How to avoid use many if
statements at the same time?
Here is an example of my code:
import random
def somefunction1(n):
m=random.randint(0,n)
if m>5:
return None
else:
return m
def somefunction2(n):
# like somefunction1
# ------way one
r1=somefunction1(10)
r2=somefunction2(someParameter)
if r1:
print(r1)
elif r2:
print(r2)
# --------way two
r1=somefunction1(10)
if r1:
print(r1)
else:
r2=somefunction2(someparameter)
if r2:
print(r2)