Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'subject:Python': 0.05; 'attributes': 0.07; 'pointers': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'situation.': 0.09; 'thread': 0.10; 'python': 0.11; 'def': 0.14; 'wed,': 0.15; 'argument': 0.15; '1.7': 0.16; 'b):': 0.16; 'nearest': 0.16; 'parameters,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'tuple,': 0.16; 'wrote:': 0.16; 'saying': 0.22; 'function,': 0.22; 'pass': 0.22; 'am,': 0.23; '2015': 0.23; 'elements': 0.23; 'passing': 0.23; "python's": 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'chris': 0.26; 'equivalent': 0.27; 'closer': 0.29; 'tutorial': 0.29; 'function': 0.30; 'values': 0.30; 'call.': 0.31; 'posts': 0.31; 'says': 0.32; 'common': 0.33; 'values.': 0.33; 'subject:?': 0.34; 'to:addr :python-list': 0.35; 'returning': 0.35; 'list': 0.35; 'possible.': 0.36; 'subject:: ': 0.37; 'received:org': 0.38; 'say': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'data': 0.40; 'modeling': 0.63; 'charset:windows-1252': 0.65; 'results': 0.66; '4.3': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Serhiy Storchaka Subject: Re: Can Python function return multiple data? Date: Thu, 04 Jun 2015 09:56:38 +0300 References: <3bbe49da-e989-4a8c-a8a9-75d3a786f508@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 193.202.118.164 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433401017 news.xs4all.nl 2841 [2001:888:2000:d::a6]:49674 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92033 On 03.06.15 02:56, Chris Angelico wrote: > On Wed, Jun 3, 2015 at 7:27 AM, fl 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 :) Closer modeling of C's model in python is to pass an object or a list as an argument and set their attributes or elements in the function. def f(a, b): a.x = 4.3 a.y = 1.7 b[:] = [45, 67] return 3