On 5/26/2014 11:15 AM, Deb Wyatt wrote:

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

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

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


Reply via email to