Do you believe it? Python also considers numbers as objects! @@@ 对象, name binding, reference count

Source: Internet
Author: User

This article learns from: http://blog.csdn.net/yockie/article/details/8474408

1. Objects

In Python, everything is Object , including 12345 Int constants. Don't believe it?? Use the dir () command to see it.

Of course, since they're all called objects. Then there must be something in common! All objects have the following three characteristics

* All have a unique identifier ID ()

* All have a definite type

* Content (or value)

Once an object is created, the identifier cannot be changed, the object type is immutable, and the content can be changed (mutable objects such as Dict, list. Constant objects such as int, string)

And an object is possible:

* There are 0 or N methods

* There are 0 or n names (the reference count is 0, or N)

2. Name

I quietly believe that the name is a reference. An object can have no or multiple names, the object itself does not know how many names, what is called, only the name itself knows what object it is pointing to. Python considers an assignment statement to be a named operation (or name binding)

The reference count for an object can be 0 or n, and the object must be accessed by name (reference), and the assignment operation in Python is a named operation (or moniker binding).

The name is valid within a certain namespace. And the only thing is that a name can only correspond to one object, while an object may have multiple names.

The meaning of a = 1 in Python:

* Create an object with a value of 1

* A is the name that points to the object

3. Binding

A binding is a reference to an object, increasing the reference count of that object.

The meaning of a = a + 1 in Python:

* Create a new object with a value of a + 1

* A This name points to the new object, the reference count of the new Object + 1, and the object reference count of a previously pointed-1

* A previously pointed object value has not changed

What actions cause a change in the reference count?

* Assign Value

* Include this object in a container (list, dict, seq)

--Increases the reference count of the object

* Leave the current namespace (the local name in the namespace will be destroyed)

* One name of the object is bound to another object

* object is removed from the container containing it

* Using the Del () method

--will reduce the reference count of the object

Do you believe it? Python also considers numbers as objects! @@@ 对象, name binding, reference count

Related Article

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.