Header Ads

Responsive Ads Here

Using all types parameters in one function

 Using all types parameters in one function



# normal parameters
# default parameters
# args ---> arguments
# kwargs ---> keyword arguments

def abc(a,b): #---> normal parameters
    return a+b

print(abc(2,3))


def abc(a=2,b=3):  # --->default parameters
    return a+b

print(abc())


def abc(*args):  # ---> *args
    x = 0
    for i in args:
        x += i
    return x

print(abc(1,2,3,4,5))


def abc(**kwargs):  # ----> **kwargs
    x = 0
    for i in kwargs.values():
        x += i
    return x

print(abc(a=2,b=4,c=6,d=8,e=10))


def func(string1, string2, *args, default=5, **kwargs):
    print(string1)
    print(string2)
    print(args)
    print(default)
    print(kwargs)

func("hello", "world", 1,2,3,4,5, a=2,b=4,c=6)

Powered by Blogger.