Multiple assignment from a function
Question: In Python, is it possible to make multiple assignments in the following manner
(or, rather, is there a shorthand):

    
    
    import random
    
    def random_int():
        return random.randint(1, 100)
    
    a, b = # for each variable assign the return values from random_int
    


Answer: Do you want to assign different return values from two different calls to your
random function or a single value to two variables generated by a single call
to the function.

For the former, use tuple unpacking

    
    
    t = (2,5)
    a,b = t #valid!
    
    def random_int():
        return random.randint(1, 100)
    #valid: unpack a 2-tuple to a 2-tuple of variables
    a, b = random_int(), random_int()
    #invalid: tries to unpack an int as a 2-tuple
    a, b = random_int()
    
    #valid: you can also use comprehensions
    a, b = (random_int() for i in range(2))
    

For the second, you can chain assignments to assign the same values to
multiple variables.

    
    
    #valid, "normal" way
    a = random_int()
    b = a
    
    #the same, shorthand
    b = a = random_int()
    

