I am a beginner programmer using python and I wonder what the best practice is for returns in a function. I have a lot of conditions, but as soon as one of them is true, I want to kill the function and return a bool value. say, we have:
a)
def foo():
if condition1:
return True
if condition2:
return True
if condition3:
return True
return False
b)
def foo():
bar = False
if condition1:
bar = True
elif condition2:
bar = True
elif condition3:
bar = True
return bar
Is one way better than another? Why? Or is this some utter junk and should be implemented in a completly different way? Is it different in other languages than in python (or, is there a "pythonic" way)? Thank you all in advance for your answers. BTW, is there a tag for best practice, or something like that?