!python --version
Let us define a function which returns single value.
def demoReturnOne(m):
return(m)
result = demoReturnOne(7)
print(result)
print(type(result))
Notice above the type of object returned, it is int.
def demoReturnTwo(m,n):
return(m,n)
result = demoReturnTwo(1,2)
result
print(type(result))
Note the type 'tuple'.
we can also collect the result in two variables since function is returning a tuple of two elements.
r1, r2 = demoReturnTwo(1,2)
r1
r2
Let us define a function which returns list.
def listF(m,n):
return([m,n])
result = listF(1,2)
result
print(type(result))
We can also assign data to two variables since list contains two elements.
a,b = listF(1,2)
a
b
Similarly we can extend the above concept to function with more than two variables.
def listF(m,n,k):
return([m,n,k])
result = listF(4,5,6)
result
a,b,c = listF(4,5,6)
a
b
c
Related Notebooks
- Pandas group by multiple custom aggregate function on multiple columns
- Five Ways To Remove Characters From A String In Python
- PySpark Replace Values In DataFrames
- Remove An Item From A List In Python Using Clear Pop Remove And Del
- How to Plot a Histogram in Python
- What is LeakyReLU Activation Function
- A Study of the TextRank Algorithm in Python
- How To Take String Input From Command Line In Python
- How To Take Integer Input From Command Line In Python