*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
Post a Comment
Write something to CodeWithAbdur!