Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35270
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <msirenef@lightbird.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'function,': 0.07; 'block.': 0.09; 'python:': 0.09; 'def': 0.10; 'a():': 0.16; 'a(object):': 0.16; 'btw': 0.16; 'class),': 0.16; 'invalid.': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'test():': 0.16; 'wrote:': 0.17; '(in': 0.18; '>>>': 0.18; 'import': 0.21; 'second': 0.24; 'pass': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'continuing': 0.27; 'execution': 0.27; 'statements': 0.29; 'class': 0.29; 'function': 0.30; 'to:addr:python-list': 0.33; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'first': 0.61; 'different': 0.63; 'believe': 0.69; 'do:': 0.91; 'same,': 0.91 |
| Date | Fri, 21 Dec 2012 00:40:01 -0500 |
| From | Mitya Sirenef <msirenef@lightbird.net> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Pass and return |
| References | <02b7f61c-6eef-4301-a0bc-6cf8473b6fa1@googlegroups.com> |
| In-Reply-To | <02b7f61c-6eef-4301-a0bc-6cf8473b6fa1@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1136.1356068405.29569.python-list@python.org> (permalink) |
| Lines | 45 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1356068405 news.xs4all.nl 6896 [2001:888:2000:d::a6]:46856 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:35270 |
Show key headers only | View raw
On 12/21/2012 12:23 AM, iMath wrote:
> Pass and return
> Are these two functions the same ?
>
> def test():
> return
>
> def test():
> pass
I believe they are the same, but these statements have
different meanings in other circumstances, e.g.:
Class A(object): pass
def test():
if x: return
else: # do something
In first example, (in a class), return would be invalid.
In second example, return would return None from function,
pass would result in continuing execution after if/else block.
Btw you can use disassemble function to look into what
these functions do:
>>> def a(): pass
>>> def b():return
>>> from dis import dis
>>> dis(a)
1 0 LOAD_CONST 0 (None)
3 RETURN_VALUE
>>> dis(b)
1 0 LOAD_CONST 0 (None)
3 RETURN_VALUE
So indeed they should be the same..
-m
--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Pass and return iMath <redstone-cold@163.com> - 2012-12-20 21:23 -0800
Re: Pass and return Mitya Sirenef <msirenef@lightbird.net> - 2012-12-21 00:40 -0500
Re: Pass and return Mitya Sirenef <msirenef@lightbird.net> - 2012-12-21 00:45 -0500
Re: Pass and return Duncan Booth <duncan.booth@invalid.invalid> - 2012-12-21 08:52 +0000
Re: Pass and return Mitya Sirenef <msirenef@lightbird.net> - 2012-12-21 12:15 -0500
Re: Pass and return Chris Angelico <rosuav@gmail.com> - 2012-12-21 17:19 +1100
Re: Pass and return Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-21 08:27 +0000
Re: Pass and return iMath <redstone-cold@163.com> - 2012-12-22 07:11 -0800
csiph-web