[Tutor] string immutability

Steven D'Aprano steve at pearwood.info
Tue Oct 25 10:23:34 CEST 2011

On Tue, Oct 25, 2011 at 12:56:56AM +0100, Alan Gauld wrote:
> On 24/10/11 20:52, Johan Martinez wrote:

> >Finally I figured it out ( __length__() ) thanks to ipython shell env.
> len(x)
> gets converted to x.__length__() by Python.

That's actually __len__ not __length__.

>>> [].__length__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute '__length__'
>>> [].__len__
<method-wrapper '__len__' of list object at 0xb7f27aac>

> But personally I just use dir() and help() and Google...

If you use dir() a lot, you might find this useful:



More information about the Tutor mailing list