[Python-Dev] In-place operators

Antoine Pitrou solipsis at pitrou.net
Tue Mar 17 23:22:00 CET 2009


Raymond Hettinger <python <at> rcn.com> writes:
> 
> I'm sure that consistency/completeness/safe_vs_sorry 
> was the reason they were added.  But, if they aren't useful, 
> they never should have been (IMO).  It wastes the time of 
> people who try to use them and then find-out that they don't 
> act as expected (the assignment doesn't take place)

>>> l = []
>>> operator.iadd(l, [5])
[5]
>>> l
[5]

The operation /does/ occur in-place for mutable types. Yes, the semantics are
non-obvious for non-mutable types, but that doesn't make it completely useless.




More information about the Python-Dev mailing list