zl程序教程

您现在的位置是:首页 >  后端

当前栏目

【说站】python位置参数如何使用

Python 使用 如何 参数 位置
2023-06-13 09:13:16 时间

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基础教程

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

收藏 | 0点赞 | 0打赏