Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35272
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'value,': 0.03; 'none,': 0.05; '21,': 0.07; 'stops': 0.07; 'lambda:': 0.09; 'none.': 0.09; 'received:mail-vb0-f46.google.com': 0.09; 'def': 0.10; 'dec': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'instance:': 0.16; 'statements,': 0.16; 'test():': 0.16; 'wrote:': 0.17; 'received:209.85.212.46': 0.18; 'load': 0.19; 'constant': 0.22; 'statement': 0.23; 'this:': 0.23; 'pass': 0.25; 'header:In- Reply-To:1': 0.25; 'executing': 0.27; 'message- id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; '"do': 0.29; 'implicitly': 0.29; 'fri,': 0.30; 'function': 0.30; 'code': 0.31; 'running': 0.32; 'to:addr:python-list': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'test': 0.36; 'does': 0.37; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'short': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'different': 0.63; 'same,': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=TksZlCgGGUoW+S0kb84bLRHKCOdcDKAwZ+WUfaO2wQc=; b=yrOTQz/0+tQPFkBSqkU9RXJv46u3ACfJxfgWjCGitohn0PbjFYePQFr8EEK4Q4PTDH ZVOXh9Gl6emkRBv/k8I2F/3KNmhlrGCx6g5+/vmRe+9AHiHnXRqIABhYQWMgvIqax6WP m7FiAVHf99PfWKcVjqhKIPqh3ePwQwwAGvhBWm8JoUVNKHH6VsoNne7+RbIBCO5/NQpe ADnCCpdwI/8dRaIuJ4vZTAwxCtMw+8ZTh3osJqjAeV6ORQ3XLnkNHY0wjxMwW3Cym0XS swPz/h+wj9NSqldX2SVCrj1rpc/ACAQFkndX8EqBODAOvLU37TU5RbSuf9KuzIaJmIaS hq4w== |
| MIME-Version | 1.0 |
| In-Reply-To | <02b7f61c-6eef-4301-a0bc-6cf8473b6fa1@googlegroups.com> |
| References | <02b7f61c-6eef-4301-a0bc-6cf8473b6fa1@googlegroups.com> |
| Date | Fri, 21 Dec 2012 17:19:29 +1100 |
| Subject | Re: Pass and return |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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.1138.1356070778.29569.python-list@python.org> (permalink) |
| Lines | 33 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1356070778 news.xs4all.nl 6901 [2001:888:2000:d::a6]:54532 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:35272 |
Show key headers only | View raw
On Fri, Dec 21, 2012 at 4:23 PM, iMath <redstone-cold@163.com> wrote:
> Pass and return
> Are these two functions the same ?
>
> def test():
> return
>
> def test():
> pass
They're different statements, but in this case they happen to
accomplish the same thing.
The pass statement means "do nothing". For instance:
while input("Enter 5 to continue: ")!="5":
pass
The return statement means "stop executing this function now, and
return this value, or None if no value".
Running off the end of a function implicitly returns None.
So what you have is one function that stops short and returns None,
and another that does nothing, then returns None. The functions
accomplish exactly the same, as does this:
test = lambda: None
All three compile to the same short block of code - load the constant
None, and return it.
ChrisA
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