函数参数
必选参数
>>> def add(x, y): # x, y 是必选参数
... print x + y
...
>>> add() # 啥都没传,不行
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: add() takes exactly 2 arguments (0 given)
>>> add(1) # 只传了一个,也不行
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: add() takes exactly 2 arguments (1 given)
>>> add(1, 2) # 数量一致,通过
3默认参数
可变参数
关键字参数
参数组合
小结
参考资料
Last updated