函数的参数类型

def func(a,b=0,*c,**d):
     print(a)
     print(b)
     print(c)
     print(d)
 func(1,2,3,4,5,name="tom",age=18)
#结果:
# 1
# 2
# (3, 4, 5)
# {'name': 'tom', 'age': 18}

“””
a***必填*参数
b**可缺省参数**,传值的话b就有值,不传的话就是0
c**可变数量**参数,可以0个,可以多个
d**关键字可变数量**参数
“”“

def func(*a):
    print(type(a))
    total = 0
    for one in a:
        total += one
    print(total)

func(1,2,3) #任意数字的求和
结果:

猜你喜欢

转载自blog.csdn.net/qq_37615098/article/details/82631801