How to return multiple values from a function in Python
![how to return multiple values from a function in python](https://pythonpoint.net/wp-content/uploads/2020/12/how-to-return-multiple-values-from-a-function-in-python-1024x576.jpg)
In Python, it is possible to return multiple values from a function. In this article, we will learn to return multiple values from a function in Python
Using Tuple:
def func(): s = 'PythonPoint' n = len(s) return s,n; #return tuple string, length = func() print(string) print(length)
Output:
PythonPoint 11
Using list
def func(): s = 'PythonPoint' n = len(s) return [s, n]; li = func() print(li)
Output:
['PythonPoint', 11]
Using Object
class sample(): def __init__(self): self.s = 'PythonPoint' self.n = len(self.s) def func(): return sample() l = func() print(l.s) print(l.n)
Output:
PythonPoint 11
Subscribe
Login
Please login to comment
0 Discussion