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: 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 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" Content-Type: text/plain; charset=UTF-8 Cc: Nir X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Mon, Feb 17, 2014 at 11:00 AM, Nir wrote: >>>> k = ['hi','boss'] >>>> >>>> k > ['hi', 'boss'] >>>> k= [s.upper for s in k] >>>> k > [, ] > > 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 >>> 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