Late-binding of function defaults (was Re: What is a function parameter =[] for?)

Chris Angelico rosuav at gmail.com
Wed Nov 25 11:29:41 EST 2015


On Thu, Nov 26, 2015 at 2:13 AM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> I agree with you: there are things about Python that surprise people.
> That's because it's a programming language, and very very little about
> programming languages is obvious.  The best we can hope for is "familiar,"
> and even then, familiar to who?  High school algebra students will at
> first be baffled by "x = x + 1", an equation which is clearly
> unsatisfiable.

And then *lots* of people are confused by "x += 1" being almost, but
not entirely, identical to the above. Actually, if there were one
change I could make to Python, it would be to redefine the augmented
assignment operators to be semantically identical to their expanded
forms; there might be some optimizations, but absolutely no difference
in effect. (Which would mean, among other things, that it would be a
very bad way to append to a list, instead of being an alias for
.extend.)

ChrisA



More information about the Python-list mailing list