How can I retrieve all the returned variables from a function?

Posted by user1447941 on Stack Overflow See other posts from Stack Overflow or by user1447941
Published on 2012-09-30T21:22:21Z Indexed on 2012/09/30 21:37 UTC
Read the original article Hit count: 156

Filed under:
|
|
import random

def some_function():
    example = random.randint(0, 1)
    if example == 1:
        other_example = 2
    else:
        return False
    return example, other_example

With this example, there is a chance that either one or two variables will be returned. Usually, for one variable I'd use var = some_function() while for two, var, var2 = some_function(). How can I tell how many variables are being returned by the function?

© Stack Overflow or respective owner

Related posts about python

Related posts about variables