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


Groups > comp.lang.python > #72043

Re: confused about the different built-in functions in Python

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed1.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.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; 'string': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tia,': 0.09; 'called.': 0.16; 'iterable': 0.16; 'len,': 0.16; 'notation': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wa,': 0.16; 'wrote:': 0.18; 'things.': 0.19; 'header:User- Agent:1': 0.23; 'received:comcast.net': 0.24; 'defined': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; '(like': 0.30; "i'm": 0.30; 'usually': 0.31; 'produces': 0.31; 'them?': 0.31; 'types.': 0.31; 'subject:the': 0.34; 'could': 0.34; 'operations': 0.35; 'but': 0.35; 'there': 0.35; 'example,': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'how': 0.40; 'different': 0.65; 'usa': 0.69; 'operation)': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ned Batchelder <ned@nedbatchelder.com>
Subject Re: confused about the different built-in functions in Python
Date Sun, 25 May 2014 22:12:19 -0400
References <648E6136A80.00000651codemonkey@inbox.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.5.0
In-Reply-To <648E6136A80.00000651codemonkey@inbox.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.10325.1401070355.18130.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1401070355 news.xs4all.nl 2847 [2001:888:2000:d::a6]:41648
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72043

Show key headers only | View raw


On 5/25/14 7:55 PM, Deb Wyatt wrote:
> I am confused about how various built-in functions are called.  Some are
> called with dot notation
>
> each_item.isalpha()
>
> and some are called like 'normal'
>
> sum(numlist)
>
> How do you know/remember which way to call them?
>
> TIA,
> Deb in WA, USA

It can be confusing.  Generally, built-in functions (like sum, len, etc) 
are used when the operation could apply to many different types.  For 
example, sum() can be used with any iterable that produces addable things.

Operations that are defined only for a single type (like .isalpha as a 
string operation) are usually defined as methods on the type.

This is not a black/white distinction, I'm sure there are interesting 
counter-examples.  But this is the general principle.

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

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


Thread

Re: confused about the different built-in functions in Python Ned Batchelder <ned@nedbatchelder.com> - 2014-05-25 22:12 -0400

csiph-web