python for loop
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Wed Apr 1 08:34:44 EDT 2009
On Wed, 01 Apr 2009 04:39:39 -0700, bearophileHUGS wrote:
> Lada Kugis:
>> (you have 1 apple, you start counting from 1 ...<
>
> To little children I now show how to count starting from zero: apple
> number zero, apple number one, etc, and they find it natural enough :-)
Ah, but that's not the same as counting ordinals from zero. Consider the
difference between an empty list, which has zero items, and a list of
length one, which as that item in position zero.
The empty list [] clearly has zero items, in zero "bins", so the bins
aren't numbered.
A list with one item [x] has one bin, labelled "Index 0".
A list with two items [x, y] has two bins, labelled Index 0 and Index 1.
A list with three items [x, y, z] has three bins, labelled Index 0, Index
1 and Index 2.
etc.
Counting "No apples plus one apple makes one apple" is easy enough. But
pointing to an apple clearly there and saying "Let's call that apple
number zero, even though there is one apple", that requires a very
special child!
--
Steven
More information about the Python-list
mailing list