Skip to main content
Practice

Using Keyword Arguments

In Python, keyword arguments refer to the method of passing values to a function by explicitly specifying the parameter names during a function call.

In programming, the term explicit refers to directly specifying values or defining behavior clearly to ensure the code's intent is transparent.


Usage of Keyword Arguments

Keyword arguments are used to pass values to a function by specifying both the parameter name and the value.

This method allows functions to be called without concern for the order of parameters.

Example of Using Keyword Arguments
# Define a function to print user information
def print_user_info(name, age, city):
print(f"name: {name}, age: {age}, city: {city}")

# Call the function with keyword arguments regardless of order
print_user_info(city="New York", name="John", age=30)
# Output: name: John, age: 30, city: New York

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.