In Python3, there are only *
parameters, as in the following function definition example.
python
>>> def foo(*, x):
print(x)
The meaning of this usage is to force the argument to be passed in keyword format for the parameter following *
, and if you pass the argument without the keyword, the following error will occur.
>>> foo(x=1)
1
>>> foo(1)
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
foo(1)
TypeError: foo() takes 0 positional arguments but 1 was given
Recommended Posts