0 Basic python-3.5 Memory management

Source: Internet
Author: User

* Variable without prior declaration

* variable does not need to specify type

* Programmer does not have a relationship with memory management

* Variable name will be recycled

* Del can release resources directly

1.python uses a reference call instead of a value call, and the recycling algorithm he uses is a reference counting algorithm, and I'll give you two examples below

x = 4y = 4aList = [1, 2, 3]blist = [1, 2, 3]print (x = y) print (x = = y) print (alist is blist) print (alist = = blist) A = 3.2B = 3.2print (A is B) print (A = = b)

Output Result:

True
True
False
True
True
True

From the output analysis we come to the following conclusion,

1) If they are purely shaped, floating-point, String type These, the return is the same result, because they are the same value, and the reference address is the same

2) If it is a list, a tuple, a dictionary, and so on, because two objects store different addresses, even if the values are the same, but if you compare the reference address, return false



2. Through del, you can delete objects

Then the above code:

x = 4y = 4print (x is y) print (x = = y) alist = [1, 2, 3]blist = [1, 2, 3]print (Alist is blist) print (alist = blist) A = 3.2b = 3.2print (A is B) print (A = = b) del aa

Output Result:

True
True
False
True
True
True
Traceback (most recent):
File "D:\myWorkSpace\CRUDFile\com\ray\test\CRUDFile.py", line +, in <module>
A
Nameerror:name ' A ' is not defined


An error message appears, and a variable is not defined because we are releasing a by Del





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

0 Basic python-3.5 Memory management

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.