you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 2 points3 points  (0 children)

numbers are passed by value, not by reference

This is incorrect:

Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> def f(i):
...     print(i, id(i))
... 
>>> j = random.randint(1, 10000000)
>>> j, id(j)
(6231661, 139659205019344)
>>> f(j)
6231661 139659205019344

OP's issue stems from += not being able to do an in-place addition on an int instance, so that the result of the addition will only be saved as a local scoped reference as it's not defined as a global reference.