python中函数的参数

 

1、

>>> def a(x):           ## 单个参数
    print(x,"and xiao ming are good friends!")

    
>>> a()
Traceback (most recent call last):
  File "<pyshell#476>", line 1, in <module>
    a()
TypeError: a() missing 1 required positional argument: 'x'
>>> a(x = "xiao qiang")
xiao qiang and xiao ming are good friends!

 

2、

>>> def a(x,y):         ## 两个参数
    print(x * y)

    
>>> a()
Traceback (most recent call last):
  File "<pyshell#481>", line 1, in <module>
    a()
TypeError: a() missing 2 required positional arguments: 'x' and 'y'
>>> a(x = 5, y = 9)
45
>>> 

 

3、

>>> def a(x,y,z):              ## 三个参数
    print(x * y / z)

    
>>> a()
Traceback (most recent call last):
  File "<pyshell#486>", line 1, in <module>
    a()
TypeError: a() missing 3 required positional arguments: 'x', 'y', and 'z'
>>> a(x = 5, y = 8, z = 3)
13.333333333333334

 

posted @ 2021-03-03 22:32  小鲨鱼2018  阅读(92)  评论(0编辑  收藏  举报