Can Python function return multiple data?

Amir Arsalan am1r.ar3alan at gmail.com
Sun Jun 7 01:45:51 EDT 2015


Tnx Steven,

You are right completly.I try more subtilize

thanks for your hint.

On Sun, Jun 7, 2015 at 10:03 AM, Steven D'Aprano <steve at pearwood.info>
wrote:

> Hi Amir, and welcome!
>
> On Sun, 7 Jun 2015 02:38 am, Amir Arsalan wrote:
>
> > you can use yield structure in python for multiple return. ex:
> >
> > def func(a):
> >     yield a*2
> >     print "a*2"
> >     yield a*3
> >     print "a*3"
> >     ...
> >
> > data = func(5) --> data = (10,15,... )
>
> That's actually wrong. If you run:
>
> data = func(5)
>
> data does NOT equal the tuple (10, 15, ...) but it is a generator object.
> Iterating over the generator will yield 10, 15 etc one item at a time.
>
>
> Please remember that the Original Poster is a beginner. He is having
> trouble
> with *basic* Python questions, like returning multiple items from a single
> function call. Showing him advanced techniques like generators, especially
> when the example you show is wrong, will just confuse him more.
>
>
>
> --
> Steven
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150607/75ee58ed/attachment.html>


More information about the Python-list mailing list