Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python coding Specification (1)

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Python coding specification:

Google publishes PEP specification

1. Variable or method naming

1) meaningful names 2) Note python built-in words and keywords 3) Private variables and function commands of class 3) the overall style is similar to C, which cannot start with a number, but with a letter or underscore

2. Indent, blank line, single line maximum character

1) indentation uses spaces 2) maximum characters should not exceed 80 as much as possible, depending on the editor. 3) Code blocks of python are indented and do not contain curly braces. 4) in a single file, the upper and lower code blocks are separated by blank lines.

3. Specify the encoding on the first line of the script: #-- coding: utf-8--

4. use as few global variables as possible, easy to maintain, and constants can be uniformly defined in the configuration file

5. The highest-level python statements are statements that are not indented-- the top-level code, which is executed when the introduced module file is introduced.

6. Python variables do not need to be declared in advance or specify a type. When assigned to other variables, methods, functions, or class instances, they are passed by reference rather than values that exist in other languages. Pay attention to the disaster caused by modification

7. The Python interpreter is responsible for memory allocation and garbage collection. Garbage collection depends on reference counting. When the reference count of an object is 0, it is at risk of being recycled.

.

Reference count: refers to the number of references to an object.

* scenarios in which reference count is increased: variable assignment, function passing, class instance assignment, or being assigned as a member of a window object (becoming a member of a container object, example:list) * reduction in reference count: when an object reference is destroyed out of the function scope, a variable is assigned another value, removed from the window object, the window object is destroyed, aliases are destroyed (destroy uses del)

9. Del deletes a reference to the object

When you delete the last reference using del, the reference variable for the object becomes 0, making the object inaccessible from now on. Any trace or debugger will add an additional reference to the object, which will delay the collection time of the object.

10. Garbage collection:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report