Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66611

Re: Why is the interpreter is returning a 'reference'?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'python,': 0.02; 'interpreter': 0.05; 'method.': 0.07; 'method,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Why': 0.09; 'python': 0.11; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'header:User- Agent:1': 0.23; 'received:comcast.net': 0.24; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; "doesn't": 0.30; '>>>>': 0.31; 'invoke': 0.31; 'this.': 0.32; 'subject:the': 0.34; 'but': 0.35; 'curious': 0.36; 'object,': 0.36; 'method': 0.36; 'skip:[ 10': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'deal,': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ned Batchelder <ned@nedbatchelder.com>
Subject Re: Why is the interpreter is returning a 'reference'?
Date Mon, 17 Feb 2014 12:08:34 -0500
References <9b80c233-ad31-44c8-8a6e-9002ab11bd0d@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host c-50-133-228-126.hsd1.ma.comcast.net
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.3.0
In-Reply-To <9b80c233-ad31-44c8-8a6e-9002ab11bd0d@googlegroups.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.7101.1392656931.18130.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1392656931 news.xs4all.nl 2830 [2001:888:2000:d::a6]:56156
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:66611

Show key headers only | View raw


On 2/17/14 12:00 PM, Nir 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'] ?
>
> This isn't a big deal, but I am just curious as to why it does this.
>

You have to invoke s.upper, with parens:

     k = [s.upper() for s in k]

In Python, a function or method is a first-class object, so "s.upper" is 
a reference to the method, "s.upper()" is the result of calling the method.

-- 
Ned Batchelder, http://nedbatchelder.com

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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