Why Do We Use This?

Akira Kiyomiya akira.kiyomiya at autodesk.com
Tue Jun 6 16:55:42 EDT 2000


Okay, what is the difference between these?

If these are same, whey do we bother using the "long" version such as
__len__(a)??

Sorry, the books I am reading do not explain very well about this issue.

a = [1,2,3,4,5,6]
len(a)                                # __len__(a)
x = a[2]                            # __getitem__(a,2)
a[1] = 7                            # __setitem__(a,1,7)
del a[2]                            # __delitem__(a,2)
x = a[1:5]                         #__getslice__(a,1,5)
a[1:3] = [10,11,12]         # __setslice__(a,1,3,[10,11,12])
del a[1:4]                        # __delslice__(a,1,4)

Thanks

Akira





More information about the Python-list mailing list