Python "why" questions

Nobody nobody at nowhere.com
Sat Aug 7 11:24:09 EDT 2010


On Sat, 07 Aug 2010 13:48:32 +0200, News123 wrote:

>> "Common sense" is wrong.  There are many compelling advantages to
>> numbering from zero instead of one:
>> 
>>   http://lambda-the-ultimate.org/node/1950
> 
> It makes sense in assembly language and even in many byte code languages.
> It makes sense if you look at the internal representation of unsigned
> numbers (which might become an index)

It also makes sense mathematically. E.g. for an MxN array stored as a
1-dimensional array, the element a[j][i] is at index

	j * N + i

with zero-based indices but:

	(j-1) * N + (i-1) + 1
	= j * N + i - N

with one-based indices.

IOW, if a language uses one-based indices, it will inevitably end up
converting to and from zero-based indices under the hood, and may end up
forcing the user to do likewise if they need to do their own array
manipulation.




More information about the Python-list mailing list