Python namespace & parameters passed between different classes of methods

Objects are independent of each other, and multiple names (within multiple scopes) can be bound to the same object. Other languages ​​are called aliases. Python
beginners usually don't understand this concept easily. When dealing with immutable basic types such as numbers, strings, and tuples , you can ignore it.
However, for
the semantics of most other types of Python code involving mutable objects, such as lists and dictionaries , aliases may have unexpected effects. This is usually done to benefit the program, because aliases are like pointers in some ways. For example, the cost of passing an object is small because the implementation only passes a pointer; if the function modifies the object passed as a parameter, the caller can see the change

The meaning of the above is, for example, when a parameter is passed in different types of methods, when the parameter is an immutable basic type such as a number, a string, a tuple, etc., changes to this parameter in the new function will not affect the original, if it is a variable object , Such as lists, dictionaries, etc., will change the original value.

Refer to
python scope and namespace
python scope and namespace—google search

Guess you like

Origin blog.csdn.net/qq_42648305/article/details/112919768