Apparently, if you need to use both keyword and positional arguments while calling your function, you have to use the positional argument first. But the following code results in an error;
def greet(first_name, l_name):
print(f'Hi, {first_name} {last_name}!')
greet('Holmes',
first_name='Harry')
So does it mean that if you're using both, you have to use the positional argument first in the required order, and only then the keyword argument?
Positional arguments must be passed in order as declared in the function. So if you pass three positional arguments, they must go to the first three arguments of the function, and those three arguments can't be passed by keyword. If you want to be able to pass the first argument out of order by keyword, all your arguments must be passed by keyword (or not at all, if they have defaults).
If it helps, Python's binding mechanism is roughly:
In your case, what this means is that:
greet('Holmes', first_name='Harry')
first binds 'Holmes'
to first_name
. Then it saw you tried to pass first_name
again as a keyword argument and objected.