*args and **kwargs In Python


# passing lists and dictionaries into *args and **kwargs

def names(monitor, *args, **kwargs):
    print(f"The monitor of our class is {monitor}. The students are;")
    for item in args:
        print(item)
    print(args)    
    print("\nLets introduce our couples!")
    for key, value in kwargs.items():
        print(f"{key} is the wife of {value}")
    print(kwargs)  
     
students = ["abdur", "kiran", "rohit", "mandela", "kumar", "asif", "azad"]
mydict = {"kiran": "rehman", "maham": "wadud", "shazia": "wahab", "ashwarya": "abishek"}

names("hammad", *students, **mydict)


# passing arguments and keyword arguments directly into *args and **kwargs

def names(monitor, *args, **kwargs):
    print(monitor)
    print(args)
    print(kwargs)
   
names("rohit", "kamal", "hamdard", "vicky", kiran="rehman", maham="wadud")



Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

What is the difference between iostream and iostream.h in cpp?

The Basic Structure of a Full-Stack Web App