平方X

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2463|回复: 0

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

[复制链接]

414

主题

709

帖子

3602

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3602
QQ
发表于 2018-6-6 12:10:57 | 显示全部楼层 |阅读模式
[md]
[More on Defining Functions](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)

# 各种类型的参数
[Python中位置参数、默认参数、可变参数、命名关键字参数、关键字参数的区别](https://blog.csdn.net/u014745194/article/details/70158926)

[Keyword (Named) Arguments in Python: How to Use Them](http://treyhunner.com/2018/04/keyword-arguments-in-python/)

[PEP 3102 -- Keyword-Only Arguments](https://www.python.org/dev/peps/pep-3102/)
## 必选参数,位置参数  
positional

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

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

## 可变参数
Arbitrary

## 命名关键字参数
Keyword-Only[/md]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|平方X ( 冀ICP备14018164号 )

GMT+8, 2024-4-27 02:23 , Processed in 0.103636 second(s), 21 queries .

技术支持:Powered by Discuz!X3.4  © 2001-2013 Comsenz Inc.

版权所有:Copyright © 2014-2018 平方X www.pingfangx.com All rights reserved.

快速回复 返回顶部 返回列表