Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35270
| Date | 2012-12-21 00:40 -0500 |
|---|---|
| From | Mitya Sirenef <msirenef@lightbird.net> |
| Subject | Re: Pass and return |
| References | <02b7f61c-6eef-4301-a0bc-6cf8473b6fa1@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1136.1356068405.29569.python-list@python.org> (permalink) |
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