+ 2

Can A Function return Multiple Values ??

Justify by giving an example please

13th May 2019, 11:07 AM
Da Talking Pigeon
Da Talking Pigeon - avatar
9 Respuestas
+ 10
You could use generator functions to yield different values each time it gets called (python)
13th May 2019, 9:26 PM
Radu Baloi
Radu Baloi - avatar
+ 6
I'd say it can't. It can return a list or a tuple with multiple values. Technically, that's pretty much the same as returning a string (which is an array of chars) and I don't think anyone would define that as "returning multiple values"
13th May 2019, 11:29 AM
Anna
Anna - avatar
+ 5
I'm not a Python expert so won't give an example but in other languages a collection or an object can be returned which contains multiple values. Multiple values can also be returned via pass by reference parameters. I will let a python programmer give you language specific examples.
13th May 2019, 11:18 AM
Sonic
Sonic - avatar
+ 4
Yes, it can. def foo(): return 1, 2 a, b = foo() #a = 1 and b = 2
13th May 2019, 11:18 AM
Théophile
Théophile - avatar
+ 4
If you return a list you can split it to return multiple values .... RETURN KEYWORD can be used only ONCE 🤔
13th May 2019, 11:44 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
Yes, it returns a list, and then we do unpacking.
13th May 2019, 11:31 AM
Théophile
Théophile - avatar
0
https://code.sololearn.com/c80xZ9OOz6c3/?ref=app So what do I need to do to this to improve it. It treats each character in the list as a value instead of the values itself like you would expect. I made it work with 1 digit numbers, but I plan to do more
21st Oct 2019, 10:18 PM
- TheLongTimeFan -
- TheLongTimeFan - - avatar
0
Nvm, I got it
31st Oct 2019, 1:25 AM
- TheLongTimeFan -
- TheLongTimeFan - - avatar