Message159809
| Author |
ezio.melotti |
| Recipients |
Daniel543, ezio.melotti, loewis |
| Date |
2012年05月02日.16:25:35 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1335975936.61.0.646052668213.issue14707@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
>>> a = ['1']
>>> b = []
>>> c = a
# now c and a refer to the same object
>>> b.append(a)
# this object is appended to b
>>> a
['1']
>>> b
[['1']]
>>> c
['1']
# a and c refer to the same object you have in b
# so all these ['1'] are actually the same object
>>> a = ['2']
# now a refers to another object
>>> c.extend(a)
# and here you are extending the object referred by c
# and the same object that you have in b
>>> b
[['1', '2']]
>>> c
['1', '2']
# so this is correct
>>> a
['2']
>>>
You can use id() to verify the identity of the objects, and read http://python.net/crew/mwh/hacks/objectthink.html for more information. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2012年05月02日 16:25:36 | ezio.melotti | set | recipients:
+ ezio.melotti, loewis, Daniel543 |
| 2012年05月02日 16:25:36 | ezio.melotti | set | messageid: <1335975936.61.0.646052668213.issue14707@psf.upfronthosting.co.za> |
| 2012年05月02日 16:25:36 | ezio.melotti | link | issue14707 messages |
| 2012年05月02日 16:25:35 | ezio.melotti | create |
|