A single *
in the method/function definition makes the positional arguments, that are given to the right of the *
, keyword-only arguments. That is, they are like keyword-arguments that are required.
If we simplify your example, we can see this further:
class ExampleClass:
def example_method(self, a, *, b):
return a, b
print(ExampleClass().example_method("First", b="Second"))
#Output: ('First', 'Second')
If we try to call the method using just positional arguments, the program crashes:
print(ExampleClass().example_method("First", "Second"))
Traceback (most recent call last):
File ".\test4.py", line 5, in <module>
print(ExampleClass().example_method("First", "Second"))
TypeError: example_method() takes 2 positional arguments but 3 were given
We can also still use optional keyword-arguments as well:
class ExampleClass:
def example_method(self, a, *, b, c="c was not set"):
return a, b, c
print(ExampleClass().example_method("First", b="Second"))
# Output: ('First', 'Second', 'c was not set')