Unpacking Argument Lists : Function Tuple Parameters : Function : Python examples (example source code) Organized by topic

C++
PHP
Python
Python Home »  Function   » [  Function Tuple Parameters  ]  Screenshots 
 



Unpacking Argument Lists






#The reverse situation occurs when the arguments are already in a list or tuple 
#but need to be unpacked for 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(36)             # normal call with separate arguments

args = [36]

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 tuple Any number of parameter: turn parameter into a tuple
2.  Arbitrary Argument Lists
3.  Parameter passing: mixed with dictionary and tuple Parameter passing: mixed with dictionary and tuple
4.  Illustrate parameter passing: tuple, type and tuple Illustrate parameter passing: tuple, type and tuple
5.  Re design the intersect and union using tuple parameter passing
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.