Unpacking Argument Lists : Function Tuple Parameters « Function « Python

Home
Python
1.2D
2.Application
3.Buildin Function
4.Class
5.Data Structure
6.Data Type
7.Database
8.Development
9.Dictionary
10.Event
11.Exception
12.File
13.Function
14.GUI Pmw
15.GUI Tk
16.Language Basics
17.List
18.Math
19.Network
20.String
21.System
22.Thread
23.Tuple
24.Utility
25.XML
Python » Function » Function Tuple ParametersScreenshots 
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 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 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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.