Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72083
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: confused about the different built-in functions in Python |
| Date | 2014-05-26 14:51 -0400 |
| References | <648e6136a80.00000651codemonkey@inbox.com> <6C977160E42.0000036Ccodemonkey@inbox.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.10353.1401130279.18130.python-list@python.org> (permalink) |
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 | Next — Next in thread | Find similar | Unroll 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