参考资料:

https://blog.csdn.net/LaoYuanPython/article/details/94469350

例子

代码:

# coding=utf-8

def f1(a, b, c):
	print(a, b, c)

def f2(a, *, b, c):
    print(a, b, c)

def main():
    f1(1, 2, 3)
    f2(1, b=2, c=3)
    f2(1, 2, 3)

if __name__ == '__main__':
    main()

实验结果:

$ python test.py
1 2 3
1 2 3
Traceback (most recent call last):
  File "test.py", line 15, in <module>
    main()
  File "test.py", line 12, in main
    f2(1, 2, 3)
TypeError: f2() takes 1 positional argument but 3 were given

分析

  • $\star$是分隔符,$\star$之前的参数不需要指定参数名,$\star$之后的参数必须要指定参数名。