Can Python function return multiple data?
Amir Arsalan
am1r.ar3alan at gmail.com
Sat Jun 6 17:55:47 EDT 2015
yield structure can able to you that return list of return by nest in
function. for example you want send a value as enter value to function and
wanna after some calculate send value as return data. 2 way for this :
a) send data as a list
b) send data with yield
example:
a)
def func(a):
a2 = a*2
print "a*2"
a3 = a*3
print "a*3"
return a2,a3
------------------------------------------------------------------------------------------
b)
def func(a):
yield a*2
print "a*2"
yield a*3
print "a*3"
if you dont understand tell me that i complete explain for u.
or send pm on hangouts,
Best,
Amir Arsalan
On Sat, Jun 6, 2015 at 10:27 PM, fl <rxjwg98 at gmail.com> wrote:
> On Saturday, June 6, 2015 at 9:39:19 AM UTC-7, 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,... )
> >
> >
> > On Wed, Jun 3, 2015 at 1:57 AM, fl <rxj... at gmail.com> wrote:
> > Hi,
> >
> >
> >
> > I just see the tutorial says Python can return value in function, it does
> >
> > not say multiple data results return situation. In C, it is possible.
> >
> > How about Python on a multiple data return requirement?
> >
> >
> >
> >
> >
> > Thanks,
> >
> > --
> >
> > https://mail.python.org/mailman/listinfo/python-list
>
> Excuse me. I input the following according to your idea, but I do not
> understand how to use it from the echo. It does not show how to use
> the multiple output results. I am a new Python user. Please give a little
> more explanation if you could.
>
>
> Thanks,
>
> >>> def func(a):
> yield a*2
> print "a*2"
> yield a*3
> print "a*3"
>
> >>> data=func(5)
> >>> data
> <generator object func at 0x02B97260>
> >>> list(data)
> a*2
> a*3
> [10, 15]
> --
> 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/4f6b2619/attachment.html>
More information about the Python-list
mailing list