平方X 发表于 2018-6-6 12:10:57

[2540]Python args 和 kwargs 及各参数的理解


(https://docs.python.org/3/tutorial/controlflow.html#more-on-defining-functions)

[理解 Python 中的 *args 和 **kwargs](http://kodango.com/variable-arguments-in-python)


# * 用于解包列表或元组,** 用于解包字典
   
> The reverse situation occurs when the arguments are already in a list or tuple but need to be unpacked for a 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:

> In the same fashion, dictionaries can deliver keyword arguments with the **-operator:

# *args 和 **kwargs 分别用于默认参数(Default Argument)和关键字参数(Keyword Arguments)

# 各种类型的参数
(https://blog.csdn.net/u014745194/article/details/70158926)

(http://treyhunner.com/2018/04/keyword-arguments-in-python/)

(https://www.python.org/dev/peps/pep-3102/)
## 必选参数,位置参数
positional

## 可选参数,默认参数
optional,default

## 关键字参数,命名参数
Keyword,named

## 可变参数
Arbitrary

## 命名关键字参数
Keyword-Only
页: [1]
查看完整版本: [2540]Python args 和 kwargs 及各参数的理解