Confused by Method(function) of a module and method ofaclass/instance

Fredrik Lundh fredrik at pythonware.com
Tue Mar 7 08:51:31 CET 2006


"Sullivan WxPyQtKinter" wrote:

> More confusing things came out to me:
> >>>str().lower()
> ''                                                  #well, this is
> understandable.
> >>>str.lower(str(),'A')
> 'a'
>
> How do you explain this result?

I get:

>>> str.lower(str(), 'A')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: lower() takes no arguments (1 given)

if you meant to write

>>> str.lower('A')
'a'

it's because "str" is the class that implements methods for the "str" type,
and, for an instance I of the class C:

    I.method()

and

    C.method(I)

are, in general, the same thing in Python

</F>






More information about the Python-list mailing list