Here It is actually returning tuple
.
If you execute this code in Python 3:
def get():
a = 3
b = 5
return a,b
number = get()
print(type(number))
print(number)
Output :
<class 'tuple'>
(3, 5)
But if you change the code line return [a,b]
instead of return a,b
and execute :
def get():
a = 3
b = 5
return [a,b]
number = get()
print(type(number))
print(number)
Output :
<class 'list'>
[3, 5]
It is only returning single object which contains multiple values.
There is another alternative to return
statement for returning multiple values, use yield
( to check in details see this What does the "yield" keyword do in Python?)
Sample Example :
def get():
for i in range(5):
yield i
number = get()
print(type(number))
print(number)
for i in number:
print(i)
Output :
<class 'generator'>
<generator object get at 0x7fbe5a1698b8>
0
1
2
3
4