当前位置: 首页 > 图灵资讯 > 行业资讯> python变长参数的使用场景

python变长参数的使用场景

发布时间:2024-06-29 21:44:51

说明

1、为函数添加装饰器。

2、若参数数量不确定,可考虑使用变长参数。

例如,在读取一些配置文件中的配置项。

3、为了实现函数的多态性,或者在继承的情况下,子类需要调用一些父类的方法。

实例

#coding:utf8

defpowersum(power,**args):
printtype(args)
print"argsis%s"%args
fork,vinargs.items():
printk,":",v
print

y={'age':18,'name':'xxmcf'}

powersum(0,**y)

powersum(0,args=y)

以上是python变长参数的使用场景,希望对大家有所帮助更多Python学习指导:python基础教程

本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。

相关文章

python3兼容python2吗

python3兼容python2吗

2025-05-09
python3 whl怎么安装

python3 whl怎么安装

2025-05-09
python 字典怎么提取value

python 字典怎么提取value

2025-05-09
python 怎样计算字符串的长度

python 怎样计算字符串的长度

2025-05-09
python 怎么样反向输出字符串

python 怎么样反向输出字符串

2025-05-09
python 怎么判断字符串开头

python 怎么判断字符串开头

2025-05-09