[issue9108] list object variable assign with multiplication sign

muzuiget report at bugs.python.org
Mon Jun 28 23:34:59 CEST 2010


New submission from muzuiget <muzuiget at gmail.com>:

platform: ubuntu 10.04 amd64, python 2.6.5 r265:79063

run below code 

a = [{}, {}, {}]
b = [{}] + [{}] + [{}]
c = [{}] * 3
print a, len(a), type(a)
print b, len(b), type(b)
print c, len(c), type(c)
a[1]["test"] = 1234
b[1]["test"] = 1234
c[1]["test"] = 1234
print a
print b
print c

the output is 

[{}, {}, {}] 3 <type 'list'>
[{}, {}, {}] 3 <type 'list'>
[{}, {}, {}] 3 <type 'list'>
[{}, {'test': 1234}, {}]
[{}, {'test': 1234}, {}]
[{'test': 1234}, {'test': 1234}, {'test': 1234}]

each dict key in variable c seen to assign with the same value.

----------
components: None
messages: 108872
nosy: muzuiget
priority: normal
severity: normal
status: open
title: list object variable assign with multiplication sign
type: compile error
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9108>
_______________________________________


More information about the Python-bugs-list mailing list