Python "why" questions

Chris Rebert clp2 at rebertia.com
Sat Aug 7 01:33:55 EDT 2010


On Fri, Aug 6, 2010 at 8:05 PM, Default User <hunguponcontent at 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



More information about the Python-list mailing list