首页 > 文章列表 > python关键字参数的多种使用

python关键字参数的多种使用

python关键字参数
495 2022-08-07

1、使用关键字时甚至可以打乱参数传递次序。

overspeed_rate(min=80, max=100, current=100)
>>> overspeed_rate(min=80, max=100, current=100)
0

2、在定义函数时,如果参数列表中的某个参数使用**参数名称,则该参数可以接受所有关键词参数。

def echo(string, **keywords):
    print(string)
    for kw in keywords:
        print(kw, ":", keywords[kw])
>>> echo(‘hello’, today=‘2019-09-04’, content=‘function’, section=3.6)

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