Unpacking Argument Lists : Function Tuple Parameters « Function « Python






Unpacking Argument Lists

Unpacking Argument Lists



#The reverse situation occurs when the arguments are already in a list or tuple 
#but need to be unpacked for a function call requiring separate positional 
#arguments. For instance, the built-in range() function expects separate start 
#and stop arguments. If they are not available separately, write the function 
#call with the *-operator to unpack the arguments out of a list or tuple:

print range(3, 6)             # normal call with separate arguments

args = [3, 6]

print range(*args)            # call with arguments unpacked from a list

           
       








Related examples in the same category

1.Any number of parameter: turn parameter into a tupleAny number of parameter: turn parameter into a tuple
2.Arbitrary Argument Lists
3.Parameter passing: mixed with dictionary and tupleParameter passing: mixed with dictionary and tuple
4.Illustrate parameter passing: tuple, type and tupleIllustrate parameter passing: tuple, type and tuple
5.Re design the intersect and union using tuple parameter passing