ADVANCED FUNCTIONS: =================== RETURNING OF COLLECTION FROM FUNCTION ===================================== 1) RETURNING OF LIST DATA FROM FUNCTION: ========================================= Syntax: return list-data-object # returning of list data from the function def returnList(tupleData): listData = list(tupleData) return listData td = eval(input("Enter a tuple data:")) ld = returnList(td) print("The List which is from the function is = ",ld) ================================================= 2) Returning of Tuple data from the function: ============================================= Syntax: return tuple-data-object # Returning a tuple data from the function def returnTuple(a,b,c,d,e,f,g,h): # tuple packing tupleData = a,b,c,d,e,f,g,h return tupleData td = returnTuple(10,True,12.23,100,False,12-24j,1234,0b110011) print("The Returned Tuple is = ",td) ======================================== 3) Returning of set data from the tuple: ======================================== Syntax: return set-data-object # Returning a set data from the function def returnSet(listData,tupleData): set1 = set(listData) # we can convert the list to set set2 = set(tupleData) # we can convert the tuple data to set return set1,set2 ld = [1,11,111,1111,11111] td = 1,3,5,7,9,11,13,15,17,19 res1,res2 = returnSet(ld,td) print("The Set1 object = ",res1) print("The Set2 object = ",res2) ============================================== 4. Returning of Dictionary from function: ========================================= Syntax: return dictionary-name # Returning the dictionary from the function def dictReturn(name,roll,age,marks): # studentRecord = dict({'stuName' : name,'stuAge' : age,'stuRoll' : roll,'stuMarks' : marks}) studentRecord = {'stuName' : name, 'stuRoll' : roll, 'stuAge' : age, 'stuMarks' : marks} return studentRecord name = input("Enter the name of the student:") roll = int(input("Enter the roll of the student:")) age = int(input("Enter the age of the student:")) marks = input("Enter the marks of the student in percentage:") record = dictReturn(name = name, roll = roll, age = age, marks = marks) print("The Student Record is = ",record) ============================================ Function as an argument to the function: ======================================== Syntax: def function1(function2): function-body def function2(): function-body # SENDING A FUNCTION AS AN ARGUMENT TO THE FUNCTION def addition(x,y,z): sum_res = x + y + z return sum_res def multiplication(x,y,z): prod_res = x * y * z return prod_res def selectedOperation(func,x,y,z): return func(x,y,z) total = selectedOperation(addition,10,20,30) print("The Sum is = ",total) product = selectedOperation(multiplication,3,5,7) print("The Product = ",product) ================================================= Higher Order Functions: ======================= function in another function Syntax: outerFunction(): innerFunction(): function-body function-body # Higher Order Function def outerFunction(text): def innerFunction(): resultText = text.upper() return resultText # return innerFunction() # print("The Text in Upper Case = ",innerFunction()) res = innerFunction() return res # print("The Text in Upper case = ",outerFunction("python")) # outerFunction("python Programming Language") print(outerFunction("python programming language")) # innerFunction()