This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2010年02月12日 14:49 by sledge76, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg99266 - (view) | Author: Andrew Chong (sledge76) | Date: 2010年02月12日 14:52 | |
This shows unexpected behavior. >>> data2 = [[]] * 4 >>> print data2 [[], [], [], []] >>> data2[0] += [(0,1)] >>> print data2 [[(0, 1)], [(0, 1)], [(0, 1)], [(0, 1)]] I added a tuple to only 0th list, but it got added to all the lists in the global list. |
|||
| msg99267 - (view) | Author: Andrew Chong (sledge76) | Date: 2010年02月12日 14:55 | |
But this works fine. >>> data = [] >>> data += [[]] >>> data += [[]] >>> data += [[]] >>> data += [[]] >>> print data [[], [], [], []] >>> data[0] += [(0,1)] >>> print data [[(0, 1)], [], [], []] |
|||
| msg99268 - (view) | Author: Florent Xicluna (flox) * (Python committer) | Date: 2010年02月12日 14:56 | |
It is by design. Please read the documentation: http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-buffer-xrange |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:57 | admin | set | github: 52165 |
| 2010年02月12日 14:56:24 | flox | set | status: open -> closed |
| 2010年02月12日 14:56:11 | flox | set | resolution: not a bug messages: + msg99268 nosy: + flox |
| 2010年02月12日 14:55:42 | sledge76 | set | messages: + msg99267 |
| 2010年02月12日 14:52:32 | sledge76 | set | type: behavior messages: + msg99266 components: + None |
| 2010年02月12日 14:49:46 | sledge76 | create | |