python variables, objects and references you really understand it

python variables, objects and references you really understand it

 

 

Variables, objects and references

Python , unlike C ++ , the Java , like other languages, they can not declare variables in advance the type of direct variable assignment. Of the Python language is concerned, the object type at run time and memory are determined. This is why we call Python language is dynamically typed reasons

Here we have the dynamic type can simply be attributed to allocate memory addresses of variables at runtime automatically determines the type of variable and variable assignment

 

Examples of
the variables used in Python and do not require an advanced type of declared variable, here to a = 1 is exemplified:

Where variables A , . 1 as an object.

Note two things:

1. untyped variables, object has type: "Type" This concept is not present in the variable, but in the object . Variable itself is generic, it just so happens that references a specific object was only at some point in time. To say in the expression, we use that variable will be immediately it was a specific object referenced replaced.

2. refer to objects: variable through a line attached to objects, variables with their ability to have put up their own connection object and (pointer connection object space), cited the establishment of a mapping relationship between the variables and objects, which It is a reference. References completed, to achieve the assignment.

 

For example x = 7

 

to sum up:

Variable is a pointer to the memory space, i.e. the space has a connection to an object;

The object is a memory space, the memory space indicated by the stored values ​​thereof;

Is formed from the reference variable is automatically subject to a mapping relationship (pointer)

 

 

Guess you like

Origin www.cnblogs.com/-wenli/p/10972368.html