Pure Python bindings

Source: Internet
Author: User

At present, many learning materials such as interpretation assignment and binding, when it is a simple variable, is an assignment, when it is a composite variable, is bound.

Note: The assignment is to re-copy the variable into a new variable, with no linkage between the two variables before and after the assignment. In C language:

int a=6;

int b;

b =a;

At this point B and a are two unrelated variables, changing the value of B does not affect A;

Binding simply binds a variable to a new name, for example, in the C + + language

int a=6;

int &b=a; (here & refers to)

At this point B is an alias of a, when changing the value of B, the value of a will change;

In Python, you have the following features

1) for simple variables:

>>> a=7
>>> B=a
>>> b=6
>>> b
6
>>> A
7

For composite variables

>>> c=[1,2]
>>> D=c
>>> d[1]=7
>>> D
[1, 7]
>>> C
[1, 7]
Therefore, some people think that the simple variable is an assignment, that is, the change of B does not affect a, two variables are independent of each other, while the composite variable is binding, d changes the impact of C, both point to the same variable, is the same variable name only.

But Python is a very pure language, so understanding is very wrong.

Please see:

>>> a=7
>>> B=a
>>> ID (a)
31892112
>>> ID (b)
31892112
>>> b=4
>>> ID (b)
31892148

So when running b=4, this is because the name of B is re-bound to the variable 4, points to another variable, and a still points to the previous variable, so the two are different.

This shows that there is only binding in Python, whether it is a simple variable or a composite variable.

Pure Python bindings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.