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


Groups > comp.lang.python > #72083

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

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!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.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'string': 0.09; 'methods,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.12; 'language.': 0.14; 'called.': 0.16; 'chr': 0.16; 'did.': 0.16; 'iterable': 0.16; 'len,': 0.16; 'magic': 0.16; 'notation': 0.16; 'ord': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.18; "python's": 0.19; 'things.': 0.19; 'meant': 0.20; 'not,': 0.20; '(the': 0.22; '>>>': 0.22; 'header :User-Agent:1': 0.23; 'defined': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; '(like': 0.30; 'originally': 0.30; "i'm": 0.30; 'usually': 0.31; 'produces': 0.31; 'them?': 0.31; 'types.': 0.31; 'lists': 0.32; 'up.': 0.33; 'guess': 0.33; 'subject:the': 0.34; 'could': 0.34; 'one,': 0.35; 'operations': 0.35; 'but': 0.35; 'there': 0.35; "i'll": 0.36; 'example,': 0.37; 'so,': 0.37; 'thank': 0.38; 'to:addr:python- list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'received:71': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'how': 0.40; 'most': 0.60; 'day.': 0.63; 'different': 0.65; 'great': 0.65; 'messed': 0.84; 'operation)': 0.84; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: confused about the different built-in functions in Python
Date Mon, 26 May 2014 14:51:05 -0400
References <648e6136a80.00000651codemonkey@inbox.com> <6C977160E42.0000036Ccodemonkey@inbox.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-71-175-90-87.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
In-Reply-To <6C977160E42.0000036Ccodemonkey@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.10353.1401130279.18130.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1401130279 news.xs4all.nl 2834 [2001:888:2000:d::a6]:46663
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72083

Show key headers only | View raw


On 5/26/2014 11:15 AM, Deb Wyatt wrote:
> <snip>
>>
>> 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
>>>
> <snip
>>>> How do you know/remember which way to call them?

>> 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.

Part of the answer is Python's history. Up to about 2.1, most built-in 
types did not have methods, though I know lists did. Ints and strings 
did not, or chr and ord might have been int.chr() and str.ord(). (The 
current string methods were originally functions in the string module.)

> Thank you for answering.  I meant to send this to the tutor list, but messed up.
 > So, I guess there isn't a magic answer to this one, and I'll learn
 > as I learn the language.  Have a great day.



-- 
Terry Jan Reedy

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


Thread

Re: confused about the different built-in functions in Python Terry Reedy <tjreedy@udel.edu> - 2014-05-26 14:51 -0400
  Re: confused about the different built-in functions in Python Marko Rauhamaa <marko@pacujo.net> - 2014-05-26 22:00 +0300
    Re: confused about the different built-in functions in Python Christian Heimes <christian@python.org> - 2014-05-26 21:47 +0200
      Re: confused about the different built-in functions in Python Marko Rauhamaa <marko@pacujo.net> - 2014-05-26 23:32 +0300
        Re: confused about the different built-in functions in Python Marko Rauhamaa <marko@pacujo.net> - 2014-05-26 23:58 +0300
          Re: confused about the different built-in functions in Python Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-05-27 11:14 +1200
          Re: confused about the different built-in functions in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-05-27 01:21 +0000
        Re: confused about the different built-in functions in Python Terry Reedy <tjreedy@udel.edu> - 2014-05-26 22:00 -0400

csiph-web