In a python function, do I need to pre-allocate a value which appears conditionally under if?
def func(x,y):
if x == 1:
z = 2
else: pass
if y == 1:
print(z)
else: pass
I see the problem here that print(z) may blow up if x != 1 and y == 1. To potentially prevent this error raiser, do I declare z = None at the beginning of the function or use try-except to print z or other ways to do? What would be the best practice?