Can Python function return multiple data?

Chris Angelico rosuav at gmail.com
Tue Jun 2 19:56:37 EDT 2015


On Wed, Jun 3, 2015 at 7:27 AM, fl <rxjwg98 at gmail.com> wrote:
> 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?

Technically, neither C nor Python can return multiple values from a
single function call. In Python, the most common way to do this is to
return a tuple, which can then be unpacked; as other posts in this
thread have shown, this can look a lot like returning multiple values,
and it's pretty convenient. In C, the nearest equivalent is passing a
number of pointers as parameters, and having the function fill out
values. Python's model is a lot closer to what you're saying than C's
model is :)

ChrisA



More information about the Python-list mailing list