DEV Community

yugalakshmi
yugalakshmi

Posted on

Keyword-Only Arguments

The * symbol is used to make parameters keyword-only.

We must pass values using parameter names.

Example:

def calculate(a, *, b):
print(a + b)

calculate(a=10, b=20)

Output:

30

Here:

  • is a keyword-only separator.

We must pass b using its name.

The following call is incorrect:

calculate(10, 20)

It gives a TypeError because b must be passed as a keyword argument.

Top comments (0)