Your question touches on one of the more esotheric and easy to misunderstand features of Python: mutables and immutables.
Here is the official documentation on mutable and immutable sequence types;
https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types
https://docs.python.org/3/library/stdtypes.html#immutable-sequence-types
As you can tell, only sequences and complex objects are mutable, and thus may be altered by the function.
Base types like integers and floats cannot be changes within the function as you describe, though strings can, as they count as sequences.
In your example, you're using an integer - so this will not work. However, with a string, array, dictionary or complex object (a class of your own design), this _will work.
If you're coming at it from another programming language like C++, think of mutables like references, and immutables like values. If you pass a value, any changes to the object referenced within the scope of the function do not live past the life of the function scope. Any changes to objects with references on them, however, do persist.
This post does an excellent job of explaining this in much more depth, and I would highly recommend skimming it;
https://medium.com/@meghamohan/mutable-and-immutable-side-of-python-c2145cf72747