cspears2002 at yahoo.com
Mon Jan 16 21:45:51 CET 2006
X = stepper()
X.data = "Spam"
--- bob <bgailer at alum.rpi.edu> wrote:
> At 12:12 PM 1/16/2006, Christopher Spears wrote:
> >I understand that you can use __getitem__ as a hook
> >modify indexing behavoir in a class. That's why
> >__getitem__ not only affects  but also for loops,
> >map calls, list comprehension, etc. For loops,
> >work by indexing a sequences from zero to a higher
> >index until out-of-bounds is reached. But why does
> >this work?
> > >>> class stepper:
> >... def __getitem__(self, i):
> >... return self.data[i]
> > >>> 'p' in X
> >What does 'in' have to do with indexing?
> What does X have to do with stepper?
"I'm the last person to pretend that I'm a radio. I'd rather go out and be a color television set."
"Who dares wins"
-British military motto
"I generally know what I'm doing."
More information about the Tutor