Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66613
| Path | csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <zachary.ware@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.013 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'interpreter': 0.05; 'attribute': 0.07; 'string': 0.09; 'objects,': 0.09; 'subject:Why': 0.09; 'python': 0.11; 'accesses': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'feb': 0.22; '>>>': 0.22; 'cc:addr:gmail.com': 0.22; 'to:name:python-list@python.org': 0.22; 'mon,': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; '(which': 0.31; '>>>>': 0.31; 'consisting': 0.31; 'themselves': 0.32; 'subject:the': 0.34; 'received:google.com': 0.35; 'doing': 0.36; 'method': 0.36; 'list': 0.37; 'expected': 0.38; 'skip:[ 10': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'hope': 0.61; 'telling': 0.64; 'upper': 0.74; "'upper'": 0.84; ':).': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=j8lgbtS3e8kdPnOYucyroOGreAJkVfL2k1V9QEbpe2s=; b=mO8RoSMrV5zCyoOsdgoWNvhzm+iK6EeScQzd3A1fX62qdqlTECC2BLL5/WtJ13P9dl RZy6dSHzo/xr33iD8lnJrPKDrrQuta4bDXOAHbEn2JlJn1NXAXvEc3PE3N89d1EdE4PM XxsbzQWByWUoeurSKVY/XgqVEbNQbayQWWRNBUndrI7U2mDZ/SFe9K5QESUt1rUo3jvK 9+uRKU/f8LwneNwz37u9j7yQGvA6SGBjQP8XhHUnaBrQR75HNTPR+IqI9oxiz2iadlog HkBmjzWzwVr6TrM10V1kELrm4oVSp56T6CtvOyTQw+ifnifeU9QSL+DAx/aylOaYgLxq YMqg== |
| X-Received | by 10.205.45.8 with SMTP id ui8mr100448bkb.134.1392657271123; Mon, 17 Feb 2014 09:14:31 -0800 (PST) |
| MIME-Version | 1.0 |
| Sender | zachary.ware@gmail.com |
| In-Reply-To | <9b80c233-ad31-44c8-8a6e-9002ab11bd0d@googlegroups.com> |
| References | <9b80c233-ad31-44c8-8a6e-9002ab11bd0d@googlegroups.com> |
| From | Zachary Ware <zachary.ware+pylist@gmail.com> |
| Date | Mon, 17 Feb 2014 11:14:10 -0600 |
| X-Google-Sender-Auth | dc0GFpHTpxXDWBpyLpKPo2h5noE |
| Subject | Re: Why is the interpreter is returning a 'reference'? |
| To | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| Cc | Nir <nirchernia@gmail.com> |
| 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.7103.1392657278.18130.python-list@python.org> (permalink) |
| Lines | 35 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1392657278 news.xs4all.nl 2848 [2001:888:2000:d::a6]:39460 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:66613 |
Show key headers only | View raw
On Mon, Feb 17, 2014 at 11:00 AM, Nir <nirchernia@gmail.com> wrote: >>>> k = ['hi','boss'] >>>> >>>> k > ['hi', 'boss'] >>>> k= [s.upper for s in k] >>>> k > [<built-in method upper of str object at 0x00000000021B2AF8>, <built-in method upper of str object at 0x0000000002283F58>] > > Why doesn't the python interpreter just return > ['HI, 'BOSS'] ? It's just doing exactly what you are telling it to :). Your list comprehension is constructing a list consisting of the 'upper' method (which are themselves objects, able to be passed around just like any other value) for each string object in list 'k'. Consider this: >>> k = ['hi', 'boss'] >>> s = k[0] >>> s 'hi' >>> s.upper # this just accesses the 'upper' attribute of 's', which turns out to be its 'upper' method <built-in method upper of str object at 0xdeadbeef> >>> s.upper() # this actually calls the 'upper' method on 's' 'HI' Change your comprehension to actually call the upper method like so: "k = [s.upper() for s in k]". It will do what you expected with that change. Hope this helps, -- Zach
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why is the interpreter is returning a 'reference'? Nir <nirchernia@gmail.com> - 2014-02-17 09:00 -0800 Re: Why is the interpreter is returning a 'reference'? emile <emile@fenx.com> - 2014-02-17 09:08 -0800 Re: Why is the interpreter is returning a 'reference'? Joel Goldstick <joel.goldstick@gmail.com> - 2014-02-17 12:08 -0500 Re: Why is the interpreter is returning a 'reference'? Ned Batchelder <ned@nedbatchelder.com> - 2014-02-17 12:08 -0500 Re: Why is the interpreter is returning a 'reference'? Marko Rauhamaa <marko@pacujo.net> - 2014-02-17 19:09 +0200 Re: Why is the interpreter is returning a 'reference'? Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-02-17 11:14 -0600 Re: Why is the interpreter is returning a 'reference'? John Gordon <gordon@panix.com> - 2014-02-17 19:17 +0000
csiph-web