1. Positional-Only Arguments (/)
In Python, / is used as a positional-only argument separator.
It means that the parameters written before / must be passed using their position. We cannot pass them using parameter names (keyword arguments).
Example:
def calculate ( a , b , / ) : print ( a + b )
calculate ( 10 , 20 ) # 30 calculate ( a = 10 , b = 20 ) # TypeError
Enter fullscreen mode
Exit fullscreen mode
TypeError: calculate() got some positional-only arguments passed as keyword arguments
Here, a and b must be passed as positional arguments.
2. Keyword-Only Arguments (*)
In Python, * can be used as a keyword-only argument separator.
It means that the parameters written after * must be passed using their parameter names.
Example:
def calculate ( a , * , b ) : print ( a + b )
calculate ( a = 10 , b = 20 ) # 30 calculate ( 10 , b = 20 ) # 30 calculate ( 10 , 20 ) # Error
Enter fullscreen mode
Exit fullscreen mode
TypeError: calculate() takes 1 positional argument but 2 were given
Here:
a can…