Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'method.': 0.07; 'subject:How': 0.09; 'python': 0.10; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'naming': 0.16; 'received:80.91': 0.16; 'received:80.91.229': 0.16; 'received:gmane.org': 0.16; 'received:list': 0.16; 'subject:array': 0.16; 'subject:object': 0.16; 'with?': 0.16; "python's": 0.18; 'stefan': 0.18; 'python?': 0.20; 'header:In- Reply-To:1': 0.23; 'header:User-Agent:1': 0.26; 'generic': 0.27; 'header:X-Complaints-To:1': 0.28; 'yes.': 0.29; 'function': 0.29; 'noticed': 0.31; 'asked': 0.31; 'received:84': 0.32; 'subject:?': 0.33; 'skip:u 40': 0.33; 'implement': 0.35; 'to:addr:python-list': 0.35; 'easier': 0.35; 'there': 0.35; 'subject:: ': 0.37; 'some': 0.38; 'sometimes': 0.38; 'method': 0.39; 'to:addr:python.org': 0.39; 'why': 0.39; 'received:org': 0.39; 'header:Received:5': 0.39; 'kind': 0.62; 'between': 0.63; 'subject:get': 0.81; 'prefers': 0.84; 'received:arcor-ip.net': 0.84; 'received:pools .arcor-ip.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Stefan Behnel Subject: Re: How can i call array_length to get the length of array object? Date: Sun, 24 Jun 2012 10:48:20 +0200 References: <1340524913.38366.YahooMailClassic@web164603.mail.gq1.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: dslb-084-056-062-205.pools.arcor-ip.net User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 In-Reply-To: <1340524913.38366.YahooMailClassic@web164603.mail.gq1.yahoo.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1340527717 news.xs4all.nl 6982 [2001:888:2000:d::a6]:43585 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:24383 gmspro, 24.06.2012 10:01: > Why are some methods/functions named in this way in python? __len__ > > underscoreunderscoreNAMEunderscoreunderscore > > Is there any speciality of naming such methods? Yes. Look up "special methods" in the documentation. You may have noticed the correspondence between len() and __len__(). That is Python's way of allowing you to implement this kind of generic functionality (sometimes referred to as a protocol). You also asked why len() is a function instead of a method. Don't you find it much easier to use one function for everything than to look up and sometimes even learn one method for each kind of object you are dealing with? Python prefers simplicity here. You want the length? Use len(). Stefan