One hour python per day (10.12)

Source: Internet
Author: User

Variables and memory management:

As with most programming languages, it is important to declare variables before using variables. The Declaration and assignment of variables in Python are performed at the same time, and are declared automatically at the time of the first assignment.

Note, however, that the type of the variable in Python is dynamic, and that both his type and memory occupancy are determined at run time, which is different from the language that is often used, such as C #.

The type of his variable and the amount of memory it occupies are determined at the time of declaration.

Reference count

In order to trace objects in memory, Python uses the simple technique of reference counting, which is to record how many references are in use within Python, and create a reference count when the object is created, but when the object is no longer needed, the reference count of the object becomes 0 o'clock. It is garbage collected.

When an object is created and assigned to a variable, the reference count of the object is set to 1. When the same object is assigned to another variable, the reference count of the object is automatically added to 1.

>>> x = 3.14     #x是第一个引用, when the reference count for this object is 1>>> y = x        #创建同一个对象的别名Y, and in fact does not create a new object for Y, but instead adds a reference count of this object to 1

How the object's reference count is incremented:
object is created: x = 3.14

Object created by alias: y = x

Passed to function by argument: FooBar (x)

or become an element of the container object: myList = [' 121 ', X, ' Hxzh ']

One hour python per day (10.12)

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.