ARGUMENTS: ========== ==> also called as "parameters". which are used to represent the data for the functions. # function definition def addition(a, b): # function header sum = a+b # function body print(sum) addition(100,200) # function call here: addition ==> function name a and b ==> arguments function without data: def addition(): a = 100 b = 200 sum = a+b print(sum) ==> two types of arguments: 1) Formal Arguments: are always define in function header (in the function definition). these are always accept the data from function call. 2) Actual Arguments: are always define in function call actual arguments can give data to formal arguments. ===================================== Types of Arguments: =================== ==> four types: 1) Positional Arguments 2) Keyword Arguments 3) Default Arguments 4) Variable Length Arguments 1) Positional Arguments ======================= def fun1(x, y): diff = x - y print(diff) # function call fun1(10,20) # -10 fun1(20,10) # 10 # Positional Arguments # WAP TO CREATE THE FUNCTION TO CHECK WHETHER THE GIVEN THREE SIDES FORM A RIGHT ANGLED TRIANGLE OR NOT. """ side ** 2 + side ** 2 == hyp ** 2 """ def checkTriangle(a,b,c): if (a ** 2 + b ** 2 == c ** 2) or (b ** 2 + c ** 2 == a ** 2) or (a ** 2 + c ** 2 == b ** 2): print("It is a Right Angled Triangle.") else: print("It is not a Right Angled Triangle.") checkTriangle(7,8,9) checkTriangle(3,4,5) checkTriangle(5,3,4) # positional arguments =========================================== 2) Keyword Arguments ==================== the arguments can pass to the function with some names are called as "keyword arguments". def fun1(a, b, c): sum = a + b + c print(sum) fun1(a = 100, c = 300, b = 200) fun1(c = 100, a = 300, b = 400) # WAP TO CREATE THE FUNCTION TO CALCULATE THE SIMPLE INTEREST. """ SI = principle * rate * time / 100; """ def simpleInterest(principle, time, rate): SI = (principle * time * rate)/100 total_amount = principle + SI print("The Total Amount = ",total_amount) # simpleInterest(500000,4,3) # simpleInterest(principle = 500000, rate = 4.5, time = 3) # keyword arguments p = int(input("Enter the principle Amount:")) t = float(input("Enter the time:")) r = float(input("Enter a rate:")) simpleInterest(rate = r, principle = p, time = t) =================================================== 3) Default Arguments ==================== def fun1(a = 0, b = 1): sum = a + b print(sum) fun1() # 1 fun1(100) # 101 fun1(100,200) # 300 def fun1(x = 0,y = 1,z = 2): product = x * y * z print(product) fun1() # function call without parameters fun1(10) # function call with one parameter fun1(10,20) # function with two parameters fun1(10,20,30) ============================================== Variable Length Arguments: ========================== def calculator(*n): # *n ==> act as tuple s = 0 for i in n: s += i # 10 30 60 100 150 210 print(s) # 10 calculator() # 0 parameters () calculator(10) # 1 parameter (10,) calculator(10,20,30,40,50,60) # (10,20,30,40,50,60) ===============================================