Keyword Argument Function
Last Updated: 01th September 2025
A keyword argument function is a function that takes input values (parameters/arguments).The arguments are passed with their corresponding parameter names.I give the arguments as a dictionary that contains the key-value pairs.
📝 Syntax:
def function_name(**kwargs):
# function body
#..
#..
#When Call it
function_name(key1=value1, key2=value2)
Example 1.
def greet(**names):
for name in names.values():
print(f"Hello, {name}!")
# Calling the function
greet(name1="Amit", name2="Rahul")
Example 2
def greet(**names):
for name in names.values():
print(f"Hello, {name}!")
# Calling the function
greet(**{"name1":"Amit", "name2":"Rahul"})
Example 3
def data(*args, **kwargs):
print(args)
print(kwargs)
# Calling the function
data(1,2,3, name1="Amit", name2="Rahul")