- 1

Indexing wishful thinking and interfacing...

So in Python lists, the first element has position 0. In numpy arrays, the first record has position 0 and the first field also has position 0 and arr[3, 5] would be the fourth record in the sixth field (record is before field and separate by comma). So much is clear. For those of us who grew up with Microsoft Excel, the references in arrays are column first then row, and 1 is the first row. In Excel the cell reference ""0 doesn't exist. A1 exists. My question is, why can't they align the logic so we don't have to remember? In other words, what's the rationale of keeping 0 instead of 1 as the first position in Python and Numpy? Zed Shaw rambles about it in his Lean Python the Hard Way but I don't buy his explanation.

9th Oct 2020, 4:30 AM
Nassim Abed
Nassim Abed - avatar
3 Réponses
+ 1
Indexes are used as an offset which when used in array tells you that so and so element is so and so blocks away from the starting address. In C language the array name holds the starting address so in order to fetch that element through a pointer variable, you had to move 0 blocks and to access the next element you have to move 1 block. Here is an example. https://code.sololearn.com/ciUBLmoH6Sr0 Now since most of the languages were built on top of the C language, they have inherited the same.
9th Oct 2020, 5:46 AM
Avinesh
Avinesh - avatar
0
the logic is already aligned since almost all popular programming languages starts with zero (Java, C, C++, Python, Javascript, Ruby, Php,..) when you learn different languages you will see how the main concepts are almost the same in programming, and Microsoft excel is not a programming language that python has to align with, rather than aligning with Microsoft excel python should align with programming common concepts and that it does
9th Oct 2020, 4:45 AM
Ruba Kh
Ruba Kh - avatar
0
Thanks all. I guess perspectives will vary based on where each one started. I started learning Python out of wanting to apply in data analysis: one book and one SL course into it, I am still using Excel and Minitab to do my analysis and visualization and statistics and I am still to see the power that Python adds to these interface-bases tools. I am now doing the DS SL course and studying a book on Python for Data Analysis.
9th Oct 2020, 6:31 AM
Nassim Abed
Nassim Abed - avatar