From: Ryan Kelly on
On Fri, 2010-08-06 at 22:05 -0500, Default User wrote:
> >From "the emperor's new clothes" department:
>
> 1) Why do Python lists start with element [0], instead of element
> [1]? "Common sense" would seem to suggest that lists should start
> with [1].

"Common sense" is wrong. There are many compelling advantages to
numbering from zero instead of one:

http://lambda-the-ultimate.org/node/1950

> 2) In Python 3, why is print a function only, so that: print "Hello,
> World" is not okay, but it must be print("Hello, World") instead?
> (Yeah, I know: picky, picky . . . )

The real question is, why was print so special in Python 2 that is can
be called without parentheses? The answer was "no reason" and it was
fixed in Python 3 to be consistent with the rest of the language.

> 3) In Python 3, why does 2.0 / 3.0 display as 0.6666666666666666, but
> 8 * 3.57 displays as 28.56 (rounded off to 2 decimal places)? And
> yet, in Python 2.6, 8 * 3.57 displays as 28.559999999999999?

Because the code for displaying floats was improved in python 3. You
can follow the fascinating discussion on issue 7117:

http://bugs.python.org/issue7117

I can't defend the rounding issues of floating point numbers in general
- it's just "one of those things" that you have to deal with. But show
me a language where floats don't have this problem.

> And we wonder why kids don't want to learn to program.

Yeah, obscure language warts, that must be the reason.

Note to self: DNFTT...


Ryan

--
Ryan Kelly
http://www.rfk.id.au | This message is digitally signed. Please visit
ryan(a)rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details



From: Vito 'ZeD' De Tullio on
Default User wrote:

>>From "the emperor's new clothes" department:
>
> 1) Why do Python lists start with element [0], instead of element [1]?
> "Common sense" would seem to suggest that lists should start with [1].

http://userweb.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html

> 2) In Python 3, why is print a function only, so that: print "Hello,
> World"
> is not okay, but it must be print("Hello, World") instead? (Yeah, I know:
> picky, picky . . . )

"There should be one-- and preferably only one --obvious way to do it."

> 3) In Python 3, why does 2.0 / 3.0 display as 0.6666666666666666, but 8 *
> 3.57 displays as 28.56 (rounded off to 2 decimal places)? And yet, in
> Python 2.6, 8 * 3.57 displays as 28.559999999999999?

http://mail.python.org/pipermail/python-dev/2009-October/092958.html

and replies

--
By ZeD

From: Chris Rebert on
On Fri, Aug 6, 2010 at 8:05 PM, Default User <hunguponcontent(a)gmail.com> wrote:
> >From "the emperor's new clothes" department:
>
> 1)  Why do Python lists start with element [0], instead of element [1]?
> "Common sense" would seem to suggest that lists should start with [1].

(In addition to the other good answers already given)
Well, "tradition" (originating from C) suggests otherwise. *Very* few
languages use 1-based indexing:
http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(array)#Array_system_cross-reference_list

> 2)  In Python 3, why is print a function only, so that: print "Hello, World"
> is not okay, but it must be print("Hello, World") instead?  (Yeah, I know:
> picky, picky . . . )

One less special case to learn; makes the language more regular and
easier to learn. It also lets one write:
f = lambda x: print(x)
Which is not possible if print is a statement.

Cheers,
Chris
--
http://blog.rebertia.com
From: Roald de Vries on
On Aug 7, 2010, at 5:46 AM, Vito 'ZeD' De Tullio wrote:
> Default User wrote:
>
>>> From "the emperor's new clothes" department:
>>
>> 1) Why do Python lists start with element [0], instead of element
>> [1]?
>> "Common sense" would seem to suggest that lists should start with
>> [1].
>
> http://userweb.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html

I think the reason why is just historical; C uses zero-based indices.
In C, an array index is an offset with respect to the pointer that the
array variable actually is, so 0 makes sense (my_array[0] == *my_array).

I'm not convinceed (yet) by Dijkstra's reasoning. *Maybe* if you want
to describe a range with two </<='s, it makes sense. But Python (nor
C, nor ...) uses that notation. I agree with the OP that the first
item in a list would most naturally be called item 1, and therefore
have index 1. (This doesn't mean I'm in favor of 1-based indices)

One of the reasons I like python so much, is that you (almost) never
have to use indices. Normally you just iterate over the elements. If I
ever need indices, it's a strong indication that I actually want a
dictionary.

Cheers, Roald


From: News123 on
On 08/07/2010 05:36 AM, Ryan Kelly wrote:
> On Fri, 2010-08-06 at 22:05 -0500, Default User wrote:
>> >From "the emperor's new clothes" department:
>>
>> 1) Why do Python lists start with element [0], instead of element
>> [1]? "Common sense" would seem to suggest that lists should start
>> with [1].
>

> "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)

For a complete beginner common sense dictates differently and there
might be confusion why the second element in a list has index 1.

However I seriously doubt, that this is a real problem.

You learn things like this on the first day of learning a programming
language.


>
>> 2) In Python 3, why is print a function only, so that: print "Hello,
>> World" is not okay, but it must be print("Hello, World") instead?
>> (Yeah, I know: picky, picky . . . )
>
> The real question is, why was print so special in Python 2 that is can
> be called without parentheses? The answer was "no reason" and it was
> fixed in Python 3 to be consistent with the rest of the language.
>
>> 3) In Python 3, why does 2.0 / 3.0 display as 0.6666666666666666, but
>> 8 * 3.57 displays as 28.56 (rounded off to 2 decimal places)? And
>> yet, in Python 2.6, 8 * 3.57 displays as 28.559999999999999?
>
> Because the code for displaying floats was improved in python 3. You
> can follow the fascinating discussion on issue 7117:
>
> http://bugs.python.org/issue7117
>
> I can't defend the rounding issues of floating point numbers in general
> - it's just "one of those things" that you have to deal with. But show
> me a language where floats don't have this problem.
>
>> And we wonder why kids don't want to learn to program.
>
I did not see the original post, but this statement sounds rather
trollish to me.

It might just be, that you can do so many things on a computer without
having to program. Watching youtube or browsing the web, chatting about
favourite PC games, the amount of SW, that you can download for almost
every task make it much less attractive to write own programs.

When my parents had their first computer there were very little games
and PC's weren't connected to the net.
so if I wanted to play with the computer I had mostly the choice between
the games called:
- basic
- pascal
- word star
- super calc

Syntax details are barely a reason to frighten children.

children start very often with typing in small programs without
understanding them, lookin at the results and changing what they believe
to understand.

Non native english speakers can write programs, before they even knew
what the english words 'if' 'else' 'while' 'list' mean. They don't care.
They learn that if 'starts' a condition and that 'else' is the beginning
of the section to be executed if the condition is not true.



> Yeah, obscure language warts, that must be the reason.
>
> Note to self: DNFTT...
>
>
> Ryan
>