Difference between *args and **kwargs in python

In any programming language we make a function to perform certain task. Sometimes we don’t know how many arguments will come from user sites, In that case we use *args.

def function_args(*args):
    for i in args:
        print(i)

call function with *args

function_args("Apple", "Laptop")

output:

Apple
Laptop

*kwargs is same as args the only difference is it is used for passing arguments with keyword.

def function_kwargs(**kwargs):
    for i in kwargs:
        print(i, kwargs[i])

call function with **kwargs

function_kwargs(fruit="Apple", device"Laptop")

output:

fruit Apple
device Laptop

Note: The words args and kwargs are just a convention, we can take any name in their place.