[Tutor] returning two values continued

Alan Gauld alan.gauld at btinternet.com
Mon Mar 24 01:37:47 CET 2008


"elis aeris" <hunter92383 at gmail.com> wrote

> def returning ():
>    a = 1
>    b = 2
>    return a, b
>
>
> ab = returning()
>
>
> does this work?
>
> if it does, is ab a tuple of 2 and [0] being a and [1] being b?

Try it in the >>> prompt, thats what its there for and will give you 
an instant answer:

>>> def returning():
...  a = 1
...  b = 2
...  return a,b
...
>>> ab = returning()
>>> print ab
(1, 2)
>>> print ab[0]
1
>>> print ab[1]
2
>>>

Does that answer your question?

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
Give a man a fish and feed him for a day
Teach him to fish and you feed him for life 




More information about the Tutor mailing list