In function some times we need to return the value at back to the calling point of the function so that the return value is further used in program , generally in other programming like C language, we only return one value but in python we return number of values.
- for returning the items we have a return keyword in which we can any type of data like int,float,list,tuple,set,dictionary etc.Program-
#return simple values
def func1():
print("we return two value")
return 1,2
#return list
def func2():
l=['one','two','three']
print("we return the list")
return l
var=func1()
print(var)
listvar=func2()
print(listvar)Output-
we return two value
(1, 2)
we return the list
['one', 'two', 'three']
In this program, we have a two function func1() and func2(), in func1() function we return 1 and 2 so it store in var which is of tuple data type and func2() return the list of items and it stores in listvar which is type of list data type then we print both the variable to show the results.