I have a function like this:
def test():
x = "3" # In actual code, this is computed
if x is None:
return None
y = "3"
if y is None:
return None
z = "hello"
if z is None:
return None
Is there a way of making the if
statement go away and abstract it with some function. I'm expecting something like this:
def test():
x = "3"
check_None(x)
y = "3"
check_None(y)
z = "hello"
check_None(z)
Ideally, check_None
should alter the control flow if the parameter passed to it is None. Is this possible?
Note: Working on Python 2.7.