Python "why" questions
ryan at rfk.id.au
Sat Aug 7 05:36:03 CEST 2010
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 , instead of element
> ? "Common sense" would seem to suggest that lists should start
> with .
"Common sense" is wrong. There are many compelling advantages to
numbering from zero instead of one:
> 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:
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...
http://www.rfk.id.au | This message is digitally signed. Please visit
ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details
More information about the Python-list