>>> def demo(a, b, *, c):#参数c必须以关键参数进行传值
print(a+b+c)
>>> demo(1, 2, c=3) #正确
6
>>> demo(1, 2, 3) #错误...,引发异常
TypeError: demo() takes 2 positional arguments but 3 were given
>>> def demo(a, b, *p, c):#参数c必须以关键参数进行传值...print(a+b+c+sum(p))
>>> demo(1, 2, 3, 4, c=5) #正确
15
>>> demo(1, 2, 3, 4, 5) #错误,引发异常
TypeError: demo...() missing 1 required keyword-only argument: 'c'
另外如果用help()函数查看sum()函数的帮助文档时,会发现sum()函数的最后一个参数是斜线,实际上这个斜线并不是...2, 3], 4) #按位置参数对start进行传值
10
>>> sum([1, 2, 3], start=4)#不允许使用关键参数,引发异常
TypeError: sum() takes no keyword