I am trying to understand the difference between non-keyword arguments an keyword arguments.
It seems to me that every argument may be also used as a keyword argument.
def print_employee_details(name, age=0, location=None):
"""Print details of employees.
Arguments:
name: Employee name
age: Employee age
location: Employee location
"""
print(name)
if age > 0:
print(age)
if location is not None:
print(location)
Here I have documented the function as having three keyword arguments.
I can choose to call this function without keyword arguments:
print_employee_details('Jack', 24, 'USA')
Or I can call this function with keyword arguments.
print_employee_details(name='Jack', age=24, location='USA')
So it seems to me that documenting all three parameters as keyword arguments as shown below is also fine.
def print_employee_details(name, age=0, location=None):
"""Print details of employees.
Keyword Arguments:
name: Employee name
age: Employee age
location: Employee location
"""
print(name)
if age > 0:
print(age)
if location is not None:
print(location)
So what really is the distinction between normal arguments and keyword arguments?