,而不能通过关键字参数形式传递
仅限位置形参栗子
def test1(a, b, c):
print(a, b, c)
test1(a=1, b=2, c=3)
def test(a,...1 2 3
1 2 3
1 2 3
test(a=1, b=2, c=3)
TypeError: test() got some positional-only arguments passed...as keyword arguments: 'a'
报错信息:test() 得到一些作为关键字参数传递的仅位置参数 ‘a'
在 / 形参前的参数只能通过位置参数传递
什么是仅限关键字参数
和仅位置参数一样...,也是 Python 3.8 的新特性
参数只传 * 代表仅关键字参数
添加了它,表示函数形参只能通过关键字参数传递,而不能通过位置参数传递
仅限关键字参数栗子
def f1(a, *, b, c):...,但提供了2个位置参数(和1个仅限关键字的参数)
在 * 形参后的参数只能通过关键字参数传递
/ 和 * 混合栗子
def f(a, /, b, *, c):
print(a, b, c)