FAQ
Thanks, Troy. I never cease to be amazed at what can be discovered by
reading the manual! <self bangs head on wall>

Mike

Troy Melhase wrote:
On 4/14/07, Mike wrote:
While trying to write a recursive function involving lists, I came
across some (to me) odd behavior which I don't quite understand. Here's
a trivial function showing the problem.
from http://docs.python.org/ref/function.html :

Default parameter values are evaluated when the function definition is
executed. This means that the expression is evaluated once, when the
function is defined, and that that same ``pre-computed'' value is used
for each call. This is especially important to understand when a
default parameter is a mutable object, such as a list or a dictionary:
if the function modifies the object (e.g. by appending an item to a
list), the default value is in effect modified.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 10 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedApr 15, '07 at 1:23a
activeApr 15, '07 at 12:23p
posts10
users7
websitepython.org

People

Translate

site design / logo © 2022 Grokbase