A dictionary containing all keyword arguments whose keyword doesn't correspond to a formal parameter : Varible length parameter « Function « Python Tutorial

Home
Python Tutorial
1.Introduction
2.Data Type
3.Statement
4.Operator
5.String
6.Tuple
7.List
8.Dictionary
9.Collections
10.Function
11.Class
12.File
13.Buildin Function
14.Buildin Module
15.Database
16.Regular Expressions
17.Thread
18.Tkinker
19.wxPython
20.XML
21.Network
22.CGI Web
23.Windows
Python Tutorial » Function » Varible length parameter 
10.5.7.A dictionary containing all keyword arguments whose keyword doesn't correspond to a formal parameter
def cheeseshop(kind, *arguments, **keywords):
    print "- Do you have any", kind, '?'
    print "- I'm sorry, we're all out of", kind
    for arg in arguments: print arg
    print '-'*40
    for kw in keywords.keys(): print kw, ':', keywords[kw]


cheeseshop('Limburger', "It's very runny, sir.",
            "It's really very, VERY runny, sir.",
            client='John Cleese',
            shopkeeper='Michael Palin',
            sketch='Cheese Shop Sketch')
10.5.Varible length parameter
10.5.1.Varible length parameter
10.5.2.variable length arguments
10.5.3.Keyword Variable Arguments (Dictionary)
10.5.4.Both keyword and non-keyword variable arguments may be used in the same function as long as the keyword dictionary is last
10.5.5.Calling Functions with Variable Argument Objects
10.5.6.** works for keyword arguments: it collects them into a new dictionary,
10.5.7.A dictionary containing all keyword arguments whose keyword doesn't correspond to a formal parameter
10.5.8.*args and **kwargs example
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.