[Pythonmac-SIG] string index bug?

Bob Ippolito bob at redivi.com
Fri Jan 30 22:16:21 EST 2004


On Jan 30, 2004, at 9:25 PM, Keith Nemitz wrote:

> This one's so unbelievable, I'd rather be ridiculed for not 
> understanding TFM than let a potential bug slip. I'm running macPython 
> 2.3 on Panther.
>
> Drop into python from Terminal. Type
>
> >>>print "food"[-3:-1]
> oo
>
> >>>print "food"[-3:0]
>
> (results in an empty line)
>
>
> huh? I mean does everyone use[-3:] instead and 0 is taboo? I'm used to 
> the Icon programming language where "food"[-3:0] returns --> ood

"food"[-3:] is equivalent to "food"[-3:None] (that is, literally, how 
it works out internally)

"food"[-3:0] is just backwards :)  If anything, it should give you 
"oof", but that's too confusing.

-bob




More information about the Pythonmac-SIG mailing list