Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78590
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'correct.': 0.07; 'string': 0.09; 'function,': 0.09; 'specific.': 0.09; 'subject:Function': 0.09; 'suggestions.': 0.09; 'yeah,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'creates': 0.14; 'thread': 0.14; 'comma': 0.16; 'display,': 0.16; 'formatting,': 0.16; 'formatting.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'parentheses': 0.16; 'shortcut': 0.16; 'str()': 0.16; 'tuple': 0.16; 'tuple.': 0.16; 'tuple;': 0.16; '(you': 0.16; 'wrote:': 0.18; 'discussion': 0.18; 'all,': 0.19; 'thu,': 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'skip:{ 20': 0.24; 'string,': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'query': 0.26; 'right.': 0.26; 'post': 0.26; 'read,': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'related': 0.29; '(like': 0.30; 'returned': 0.30; 'said,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'easier': 0.31; 'omitted': 0.31; 'own,': 0.31; 'steven': 0.31; 'values.': 0.31; 'running': 0.33; 'there,': 0.34; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'everyone.': 0.36; 'returning': 0.36; 'thank': 0.38; 'list,': 0.38; 'pm,': 0.38; 'little': 0.38; 'does': 0.39; "you're": 0.61; 'such': 0.63; 'different': 0.65; 'percent': 0.68; 'fantastic': 0.74; 'obvious': 0.74; 'good!': 0.84; 'here...': 0.84; 'parser,': 0.84; 'to:none': 0.92 |
| 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:cc :content-type; bh=fLzFXn7se4c4hRgkMImJwiNSpggmFq3qrpiv59fyYRg=; b=dEGRKC9rnQPtFd+vBwA0RQGnNarycEiiUJl1aHk/Ys92dzIa6Sy0HYEp70AmCOoat2 sTF9jtm0JX4IVo9AnhGmUVeTZdx3tI81wTw7F7ct6KwAdoBI5eG2AUrsazgVRlKIhjg5 zll2g/VYlrcKnXUYvotEnIxou6A20fiPshi1dVdESkA6bmZtwr/GWIiK4NHK/tv+vv3c hQosWLFIrkhHzRoP5I5quxLAVST7GuWOHbWuo1PMeKRRo3r+XAoHWv0c6Hx10bBCV0oG I4Kjvv1bpM0cUd6dm01sPEXBwQEN9TmHoxf9tN3qgchoriqI05Joe/zCVOQH9gChGn6o epAQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.176.202 with SMTP id ck10mr2741574igc.2.1412240087373; Thu, 02 Oct 2014 01:54:47 -0700 (PDT) |
| In-Reply-To | <loom.20141002T104014-395@post.gmane.org> |
| References | <loom.20141002T003356-994@post.gmane.org> <loom.20141002T104014-395@post.gmane.org> |
| Date | Thu, 2 Oct 2014 18:54:47 +1000 |
| Subject | Re: Function passed as an argument returns none |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| 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 | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14546.1412240090.18130.python-list@python.org> (permalink) |
| Lines | 53 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1412240090 news.xs4all.nl 2931 [2001:888:2000:d::a6]:60488 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:78590 |
Show key headers only | View raw
On Thu, Oct 2, 2014 at 6:46 PM, Shiva
<shivaji_tn@yahoo.com.dmarc.invalid> wrote:
> Hi All,
>
> Thank you everyone. This is fantastic - I post a query and go to sleep and
> by the time I get up there is already a nice little thread of discussion
> going on.....
Yeah, that's what python-list is like! Busy list, lots of opinionated
people here...
> By the way, I sorted it with all your suggestions.
>
> def donuts(count):
> if count <= 9: #This had to be 9 instead of 5 as per the question req.
> return 'Number of donuts: {0}'.format(count)
> else:
> return 'Number of donuts: many'
Looks good!
> So to summarise what I learnt:
>
> * Just 'return' returns None - it is not related to what you print inside
> the function.If you want something specific out of a function return
> something specific.
Correct. As Steven and I said, printing is unrelated to returned
values. Running off the end of a function, or using "return" on its
own, is the same as "return None".
> * return 'Number of donuts: ',count returns a tuple like:
> ('Number of donuts: ',9)
Right. The comma creates a tuple; the parentheses are printed on
display, to make it easier to read, but it's the comma that does it.
The comma has different meaning in some places, such as a function
call (like print), but otherwise it'll create a tuple.
> * To just print the string without returning it as tuple , use string
> formatting.
Yep! You're three for three. There are other ways to do things (you
could use str() and concatenation, or percent formatting, or any
number of ways), but they all do the same thing: they construct a
single string, which you can then return. Incidentally, when you use
.format() as you do there, the number 0 can be omitted - it's obvious
to the parser, so you can shortcut it:
>>> "Hello, {}!".format("world")
'Hello, world!'
ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Function passed as an argument returns none Chris Angelico <rosuav@gmail.com> - 2014-10-02 18:54 +1000
csiph-web