-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path037_ReturnUsingClass.py
More file actions
31 lines (24 loc) · 1018 Bytes
/
037_ReturnUsingClass.py
File metadata and controls
31 lines (24 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
Returning Multiple Values in Python
There are four ways to return multiple values in Python;
1. Using Object :
Similar to C/C++ and Java, we can create a class to hold multiple values and return an object of the class.
2. Using Tuple :
A Tuple is a comma separated sequence of items. It is created with or without (). Tuples are immutable.
3. Using List :
A list is like an array of items created using square brackets. They are different from arrays as they can contain items of different types. Lists are different from tuples as they are mutable.
4. Using Dictionary :
A Dictionary is similar to hash or map in other languages. See this for details of dictionary.
"""
""" Returning values from a method using class """
class Test:
def __init__(self):
self.str = "Python"
self.x = 20
# This function returns an object of Test
def fun():
return Test()
# Driver code to test above method
t = fun() # We can also write -> t = Test()
print(t.str)
print(t.x)