Recently, I start to see stars and slashes in Python's function definitions. They are like regular function's arguments, but nowhere used inside the function. What is their role?
It is the new feature implemented in Python 3.8. It allows to mark strictly positional arguments and strictly keyword arguments. For example, given a function:
def example(a, b, /, c, d, *, e, f): pass
- All that stands BEFORE slash - all that arguments (a and b) are only positional. So, when you try to assign values to them using keywords, you will have an error.
- All arguments that stand AFTER star (e and f) are only keyword arguments. When you try to assign values to them without mentioning their name - you will have an error.
- Arguments between slash and star (c and d) are normal Python arguments that can be either positional or keyword-assigned.