How does one write a function that increments a number?

anonymousnerd at gmail.com anonymousnerd at gmail.com
Sat Jun 25 00:53:03 EDT 2005


  Apologies if this question seems stupid: How does one write a
function that increments a value in Python? When I tried, the variable
never changed.
The session went like this:
>>> def incr(counter):
	counter = int(counter)
	counter += 1

>>> counter = 1
>>> incr(counter)
>>> print counter
1
>>>

Thanks in advance,
Vaibhav




More information about the Python-list mailing list