您的当前位置:首页正文

python关键字参数的多种使用

来源:花图问答

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)

以上就是python关键字参数的多种使用,希望对大家有所帮助。更多Python学习指路:

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