[Edu-sig] teaching Python

Chris Stromberger chris.stromberger at gmail.com
Fri Apr 23 20:30:04 CEST 2010


Ouch, that's bizarre.

On Fri, Apr 23, 2010 at 12:44 PM, Mark Engelberg <
mark.engelberg at alumni.rice.edu> wrote:

> They have every right to be confused.  Who would guess that Python
> evaluates optional arguments once at compile-time?  Heck, I've used
> Python for years and I wouldn't have been able to tell you off the top
> of my head how Python handles this code.
>
> That reminds me of a similar gotcha I've unfortunately run into on
> more than one occasion.
>
> # intialize a to be a list of 5 empty lists
> a = 5*[[]]
> # push a value onto the first list.
> a[0].append(1)
>
> What's a?
>
> --Mark
>
> (P.S.  Stuff like this drives me nuts, which is why I find myself
> gravitating more and more to languages with a richer set of immutable
> data structures, e.g., Clojure/Scala/etc., where both of these gotchas
> would become a non-issue.  I would love to see more immutable
> datatypes in Python other than numbers/strings/tuples, although
> realistically, I'd say that's unlikely to happen.)
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20100423/99d3aa3c/attachment.html>


More information about the Edu-sig mailing list