Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Draft saved
Draft discarded
Cancel
11
  • x=list() is executed exactly once when the def is executed. So the default value for x of all calls to f refer to the same object. Commented Jun 27, 2014 at 9:00
  • 1
    @LutzHorn Read on; that isn't the question. Commented Jun 27, 2014 at 9:00
  • The question is: "is there any shorter or better way to solve this problem? Will it ever be?". The answer is: No, because (see above). Commented Jun 27, 2014 at 9:01
  • 1
    Related: Why the "mutable default argument fix" syntax is so ugly, asks python newbie Commented Jun 27, 2014 at 9:05
  • 1
    Only improvement you can do here is to use x is None instead of ==. Commented Jun 27, 2014 at 9:08

lang-py

AltStyle によって変換されたページ (->オリジナル) /