Python 函数声明中单独的正斜杠(/)和星号(*)是什么意思
def func(a, /, b, *, c):
print(a, b, c)
func(1, 2, c=3) # ok
func(1, b=2, c=3) # ok
func(a=1, 2, 3) # err/规定了在其之前的参数都必须是 positional argument,而不能是 keyword argument;之后的不管,两种均可;*规定了在其之后的参数都必须是 keyword argument,而不能是 positional argument;之前的不管,两种均可;当两者同时出现时,
/必须在*之前;
使用示例
Last updated