You are here: Home / Topics / Return list by function in python

Return list by function in python

Filed under: Python on 2022-08-31 16:24:28

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.

About Author:
Y
Yogesh     View Profile
I am Yogesh Sharma. I found this website very useful for all the students. It is a very good website for learning thousands of multiple choice questions. Basically it is like a community website. Everyone can add questions so am I. I will add mcqs in this website to help you.