Why Python does *SLICING* the way it does??

Javier Bezos no.spam at see.below.es
Wed Apr 20 14:18:28 EDT 2005


"James Stroud" <jstroud at mbi.ucla.edu> escribió en el mensaje
news:mailman.2195.1114020091.1799.python-list at python.org...
> I like this, it works for any integer.
> >>> str="asdfjkl;"
> >>> i=-400
> >>> print str[:i]+str[i:]
> asdfjkl;
> >>> i = 65534214
> >>> print str[:i]+str[i:]
> asdfjkl;

Actually, this has no relation with the half-open
slices but with the fact that if i goes beyond
the limit of the string then Python, wisely, doesn't
raise an error but instead return the string until
the end. When people say that half-open slices work
for every i, they are tinking in the case i=0.

Javier

___________________________________________________________
Javier Bezos                | TeX y tipografía
jbezos at wanadoo dot es    | http://perso.wanadoo.es/jbezos
............................|...............................
CervanTeX (Spanish TUG)     | http://www.cervantex.org









More information about the Python-list mailing list