Wednesday 17 February 2021

Types of arguments in Python

 #Positional Arguments


'''

def show(a,b):

    print(a-b)



show(5,2)

show(2,5)

#show(5)

#show(5,2,6)



#Default Arguments

def show1(a,b=2):

    print(a-b)


show1(5)

show1(5,3)



def show2(a=10,b=5):

    print(a-b)


show2()

show2(5)

show2(5,3)


def show3(a=10,b):

    print(a-b)


#show3()

#show3(5)

show3(5,3)


Keyword arguments/Named Arguments


def display(a,b):

    print(a-b)


display(a=5,b=2)

display(b=2,a=5)

#display(a=5,2)

display(5,b=2)

#display(b=2,5)

display(5,2)



Variable Length Arguments

'''


def sum(*n):

    s=0

    for i in n:

        s=s+i

    print("Sum=",s)



sum()

sum(5)

sum(5,10)

sum(5,10,15)


No comments:

Post a Comment