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月11日 15:26 by mattrussell, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg99219 - (view) | Author: Matthew Russell (mattrussell) | Date: 2010年02月11日 15:26 | |
Tuples, as we know are designed to immutable. Hence I'm questioning if the following behavior is considered a defect: >>> t = (1, 2) >>> t += (1, 2, 3) >>> t (1, 2, 3) ? |
|||
| msg99220 - (view) | Author: Jean-Paul Calderone (exarkun) * (Python committer) | Date: 2010年02月11日 15:28 | |
Your output looks fishy. Anyway, the behavior of += isn't a bug: >>> a = b = (1, 2) >>> a += (1, 2, 3) >>> a (1, 2, 1, 2, 3) >>> a is b False >>> It's confusing, to be sure, but no mutation is going on. += is only in-place if applied to something that supports mutation this way (by implementing __iadd__). |
|||
| msg99221 - (view) | Author: Tim Golden (tim.golden) * (Python committer) | Date: 2010年02月11日 15:32 | |
Just think about it for a minute: t = (1, 2) print id (t), t t += (1, 2, 3) print id (t), t Not mutating, merely creating a new new object and giving it the same name |
|||
| msg99225 - (view) | Author: Matthew Russell (mattrussell) | Date: 2010年02月11日 15:40 | |
Yes, the output is fishy indeed my bad (paste error). Tim: I hadn't thought for long enough or thought to check with the id builtin - nice catch. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:57 | admin | set | github: 52158 |
| 2010年02月11日 17:45:27 | rhettinger | set | resolution: not a bug |
| 2010年02月11日 15:40:19 | mattrussell | set | status: open -> closed messages: + msg99225 |
| 2010年02月11日 15:32:40 | tim.golden | set | nosy:
+ tim.golden messages: + msg99221 |
| 2010年02月11日 15:28:21 | exarkun | set | nosy:
+ exarkun messages: + msg99220 |
| 2010年02月11日 15:26:27 | mattrussell | create | |