python函数参数
来源:互联网 发布:知乎和知乎日报的区别 编辑:程序博客网 时间:2024/06/07 06:34
Python有四种函数参数:
- Required arguments
- Keyword arguments
- Default arguments
- Variable-length arguments
第1,2,4种参数都是相对于调用来说的,第3种参数是相对于函数定义来说的。
Required arguments
Required arguments are the arguments passed to a function in correct positional order. Here, the number of arguments in the function call should match exactly with the function definition.
即调用函数时,函数参数的数量和位置必须完全匹配函数的定义情况。
Keyword arguments
When you use keyword arguments in a function call, the caller identifies the arguments by the parameter name.
This allows you to skip arguments or place them out of order because the Python interpreter is able to use the keywords provided to match the values with parameters.
e.g.
def func(str): print strfunc(str=u'haha')
Default arguments
A default argument is an argument that assumes a default value if a value is not provided in the function call for that argument.
Variable-length arguments
You may need to process a function for more arguments than you specified while defining the function. These arguments are called variable-length arguments and are not named in the function definition.
e.g.
def generic(*args, **kwargs): print args print kwargsgeneric('1', 1, nima=1, nida=2)
(‘1’, 1)
{‘nima’: 1, ‘nida’: 2}
可见,required arguments的变长参数被带有一个*的变量接收(形成一个tuple),keywords arguments的变长参数被带有两个*的变量接收(形成一个dict)。
Ref:
http://www.tutorialspoint.com/python/python_functions.htm
- python函数参数
- Python函数参数
- python函数星号参数
- Python函数参数中的*,**
- python 函数参数传递
- python 函数多参数
- python函数星号参数
- 关于python函数参数
- Python函数参数总结
- Python中函数参数
- Python 函数 参数
- python 函数参数问题
- python函数参数详解
- [python]函数的参数
- python函数--参数收集
- python 函数参数
- python 函数的参数
- Python的函数参数
- 1-3-2 ARM指令分类
- 指令重排与happens-before
- eclipse 快捷方式 存着自己看
- View的测量
- RxJava 与 Retrofit 结合的最佳实践
- python函数参数
- spring中常用工具类
- 总结
- 《产品前线:48位一线互联网产品经理的智慧与实战》读书笔记3
- (转载)如何理解RxJava中的join操作
- 垂直居中的一个方案
- 从一个简洁的进度刻度绘制中了解自定义View的思路流程
- 网易笔试-2016研发工程师题-小易的升级之路
- 问题 V 一元三次方程求解