原文标题:python位置参数如何使用
说明
1、实参必须按照正确的顺序传输到函数中。
2、调用函数中指定的实际参数的数量必须与形式参数的数量一致,否则Python解释器会抛出TypeError异常,并提示缺乏必要的位置参数。
实例
def girth(width , height): return 2 * width+height #调用函数时,必须传递 2 个参数,否则会引发错误 print(girth(3)) 运行后报Traceback错误。 Traceback (most recent call last): File "/Volumes/Develop/Python_learn/PycharmProjects/python_demo_1/demo/function/locate_fun.py", line 6, in <module> print(girth(3)) TypeError: girth() missing 1 required positional argument: 'height'
以上就是python位置参数的使用,希望对大家有所帮助。
[版权声明]
本文标题:python位置参数如何使用作者:python学习
本文链接:http://www.ccpit.org.cn/jichu/jc1485.html——此文章系本站原创/整理,转载请标明出处、原标题、链接