好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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学习指路: python基础教程

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

查看更多关于python关键字参数的多种使用的详细内容...

  阅读:27次