I see plenty of good advice about how to return multiple values in a function, but what's the preferred way to also handle checking other returns like False?
For example:
def f():
if condition1:
return False
else:
return x, y, z
x, y, z = f()
I can verify if [x, y, z] is not None:
but how about also checking for False
? Is it just if [x, y, z] is not None and f() is not False:
or is there a superior way?
I think it'd help to have more consistency:
def f():
if condition1:
return False, None
else:
return True, (x, y, z)
success, tup = f()
if success:
x, y, z = tup
# use x, y, z...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With