Python Success stories

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Apr 22 15:35:27 EDT 2008


En Tue, 22 Apr 2008 13:50:54 -0300, Jérémy Wagner <jeremy.wagner at laposte.net> escribió:

> Sure. Python is more readable than Perl, though I have found Python
> to have a weird behavior regarding this little issue :
>
> How can you explain that Python doesn't support the ++ opeator,
> whereas at the same time it does support the += operator ???
>
> No python developer I know has been able to answer that.

Because Python doesn't follow the "boxed variables" model. In other languages i++ changes the "value" stored inside the box "i", but the box itself (the variable) is still the same. Python doesn't have boxes, it has names that refer to objects. For all builtin numeric types, i += 1 creates a *new* object with the resulting value and makes the name "i" refer to this new object.
i++ would be confusing because it looks like a mutating operation over i, but in fact it would be an assignment.

-- 
Gabriel Genellina




More information about the Python-list mailing list