If you meant that you cannot predict the number of return values ββof a function, then
i, j = hillupillu()
will raise the value ValueError
if the function does not return exactly two values. You can catch this with the usual construct try
:
try:
i, j = hillupillu()
except ValueError:
print("Hey, I was expecting two values!")
This follows the general Python idiom of "asking for forgiveness, not permission." If it hillupillu
can raise ValueError
, you need to do an explicit check:
r = hillupillu()
if len(r) != 2:
print("Hey, I was expecting two values!")
i, j = r
, None
, None in (i, j)
if
-clause.