If you meant that you can't predict the number of return values of some function, then
i, j = hillupillu()
will raise a ValueError
if the function doesn't return exactly two values. You can catch that with the usual try
construct:
try:
i, j = hillupillu()
except ValueError:
print("Hey, I was expecting two values!")
This follows the common Python idiom of "asking for forgiveness, not permission". If hillupillu
might raise a ValueError
itself, you'll want to do an explicit check:
r = hillupillu()
if len(r) != 2: # maybe check whether it's a tuple as well with isinstance(r, tuple)
print("Hey, I was expecting two values!")
i, j = r
If you meant that you want to check for None
in the returned values, then check for None in (i, j)
in an if
-clause.