def func():
global count
count += 1
if __name__ == '__main__':
count = 0
print(count)
func()
print(count)
As defined in the python documentation:
If we have a mutable object (list, dict, set, etc.), we can use some specific operations to mutate it and all the variables that refer to it will see the change.
If we have an immutable object (str, int, tuple, etc.), all the variables that refer to it will always see the same value, but operations that transform that value into a new value always return a new object.
Its clearly mentioned in the 2nd statement that int is immutable, but if you run the python code above with global it seems to be working.
Any explanation that anyone can provide here, or i am missing something here?