On 2 ene, 14:21, Ulrich Eckhardt wrote:
> vsoler wrote:
> > class stepper:
> > def __getitem__(self, i):
> > return self.data[i]
>
> > X=stepper()
> > X.data="Spam"
> > for item in X:
> > print item,
>
> > ... what I get is S p a m which seems logical to me since the
> > lo
vsoler wrote:
> class stepper:
> def __getitem__(self, i):
> return self.data[i]
>
> X=stepper()
> X.data="Spam"
> for item in X:
> print item,
>
> ... what I get is S p a m which seems logical to me since the
> loop stops after the 4th character.
I think you're mistaking
On Jan 2, 3:50 pm, vsoler wrote:
> My question is: why does this second script not stop after printing
> number 3? what made the first one stop while the second one will not?
First one will raise IndexError when string is over, second one won't.
--
http://mail.python.org/mailman/listinfo/pytho