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

From Ned Batchelder <ned@nedbatchelder.com>
Subject Re: confused about the different built-in functions in Python
Date 2014-05-25 22:12 -0400
References <648E6136A80.00000651codemonkey@inbox.com>
Newsgroups comp.lang.python
Message-ID <mailman.10325.1401070355.18130.python-list@python.org> (permalink)

Show all headers | 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