Return list by function in python by R4R Team

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.


#return simple values
def func1():
print("we return two value")
return 1,2

#return list
def func2():
print("we return the list")
return l


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.

Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!