Somthing strange with list as default argument
From: Julien Sagnard (julien.sagnard.withoutthis_at_free.fr)
Date: 09/22/04
- Next message: Michael Foord: "POST from a CGI"
- Previous message: Paul Rubin: "Re: Why not FP for Money?"
- Next in thread: Alex Martelli: "Re: Somthing strange with list as default argument"
- Reply: Alex Martelli: "Re: Somthing strange with list as default argument"
- Reply: Duncan Booth: "Re: Somthing strange with list as default argument"
- Reply: Sam Holden: "Re: Somthing strange with list as default argument"
- Reply: Julien Sagnard: "Re: Somthing strange with list as default argument"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 22 Sep 2004 10:19:45 +0200
Hi all,
When passing a list as default argument for a function, only one list is
created for all calls.
exemple:
>>> def f(a=[]):
... a.append("x")
... print a
...
>>> f()
['x']
>>> f()
['x', 'x']
>>> f()
['x', 'x', 'x']
>>> f()
['x', 'x', 'x', 'x']
>>>
I'm not found any reference of this. Is it a bug ?
I'm working on Windows 2000 with python 2.3.4
- Next message: Michael Foord: "POST from a CGI"
- Previous message: Paul Rubin: "Re: Why not FP for Money?"
- Next in thread: Alex Martelli: "Re: Somthing strange with list as default argument"
- Reply: Alex Martelli: "Re: Somthing strange with list as default argument"
- Reply: Duncan Booth: "Re: Somthing strange with list as default argument"
- Reply: Sam Holden: "Re: Somthing strange with list as default argument"
- Reply: Julien Sagnard: "Re: Somthing strange with list as default argument"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|