Python ' s Coding Style

Source: Internet
Author: User

A programmer's good qualities can be seen in his code style.

The official Python Developer's Guide, PEP8, lists style guides for Python Code.

Excerpts from the Python ' s tutorial are listed.

1. Indent with 4 spaces instead of the TAB key.

2. Make each line not more than 79 characters, the purpose is small screen user also can read very well.

3. Use an empty line to separate functions, classes, and functions from the large blocks of code.

4. If possible, write the comments in one line.

5.Use docstrings. Use a document string. (Ps. This can be used well)

6. Use a space on both sides of the operator, as well as a space after the comma, but do not use spaces where the parentheses are connected.

7. Maintain the consistency of the class name and function name; The Convention is that the class name uses the camelcase format, and the method name and function name are in lower_case_with_underscres form. Always use self as the first parameter name of a method.

8. If your code is intended to be used in an international environment, do not use some novel encoding format, Pyhton's default encoding format is UTF-8.

9. Similarly, if the reader or maintainer of the code is basically not using the requirements of another language, then do not use non-ASCII characters in the identifiers.

Ps:camelcase is also called camel writing, divided into two kinds, one is the small camel writing, CamelCase, one is the big camel writing, CamelCase, also known as Pascal writing.

The lower_case_with_underscores is a lowercase letter, but is connected with an underscore.

Python ' s Coding Style

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.