Why Python does *SLICING* the way it does??
Roy Smith
roy at panix.com
Wed Apr 20 13:28:23 EDT 2005
Terry Hancock wrote:
>> I used to make "off by one" errors all the time in both C and Fortran,
>> whereas I hardly ever make them in Python.
Part of the reason may be that most loops over lists involve
iterators, where the details of the index limits are hidden. In
Python, you write:
for item in myList:
blah
but in C and Fortran you would write:
for (i = 0; i < MAXLIST; ++i) {
blah;
do 10 i = 1, MAXLIST
10 blah
both endpoints are mentioned explicitly. C++/STL also uses iterators,
but the syntax is repulsive.
More information about the Python-list
mailing list