这是来自 Google AppEngine 教程的片段。
application = webapp.WSGIApplication([('/', MainPage)], debug=True)
我不太确定 debug=True 在构造函数调用中做了什么。 它是否创建一个名称为 debug 的局部变量,将 True 分配给它,并将其传递给构造函数,或者这是一种在构造函数中设置类实例成员变量值的方法?
请您参考如下方法:
Python 函数接受关键字参数。如果你这样定义一个函数:
def my_func(a, b='abc', c='def'):
print a, b, c
你可以这样调用它:
my_func('hello', c='world')
结果将是:
hello abc world
您还可以使用特殊语法支持动态关键字参数:
def my_other_func(a, *b, **c):
print a, b, c
*b表示b变量将把a之后的所有非命名参数作为一个元组对象。**c表示c变量将采用所有命名参数,作为dict对象。
如果你这样调用函数:
my_other_func('hello', 'world', 'what a', state='fine', what='day')
您将获得:
hello ('world', 'what a') {'state': 'fine', 'what': 'day'}
