How does one write a function that increments a number?

George Sakkis gsakkis at rutgers.edu
Sat Jun 25 02:12:21 EDT 2005


<anonymousnerd at gmail.com> wrote:

> Wait... so this means it is impossible to write a function that
> increments an integer without turning the integer into a list?

The short answer is no you can't, because integers are immutable (as
well as floats and strings among others). The longer answer is you can
create a, say, MutableInt class whose instances behave as modifiable
integers. Most probably you don't really need this, but if you think
you do, others in the list will sketch out how.

George




More information about the Python-list mailing list