Design for slices

Darren New dnew at san.rr.com
Wed Jan 31 23:47:58 EST 2001


> Why is the first character in the string x defined as x[0] and
> not x[1]? 

Along with all the mathematical answers, there's also the answer that (most)
computer languages only do one thing at a time. If you're counting and
processing the elements of a string (or list, or whatever), you do it in
three steps:

1) Am I done yet?
2) Process the current item.
3) Move to the next item.

The first step is really "Does the number of items I processed equal the
number of items in the list/string?" And before you process any, the number
of items you've processed is zero.

Try counting out 10 pennies from your hand to the desk, but don't say the
number at the same time your hands are moving. What did you say after you
moved one penny? "One." What did you say *before* you moved any pennies?

-- 
Darren New / Senior MTS & Free Radical / Invisible Worlds Inc.
San Diego, CA, USA (PST).  Cryptokeys on demand.
                 Ignorance can be cured. Naivety cures itself.



More information about the Python-list mailing list