Python Coding Style/python Programming style

Source: Internet
Author: User

#from "Python 2.7.9 Documentation"

  • Use 4-space indentation, and No tabs.

  • #使用4空格缩进, do not use the tab indent
  • Wrap lines so they don ' t exceed characters.

  • Split lines to ensure that no more than 79 characters per line
  • Use blank lines to separate functions and classes, and larger blocks of code inside functions.

  • The function and the class are separated by a blank line, including chunks of code that are separated by a blank line
  • When possible, put comments on a line of their own.

  • Note a single row
  • Use Docstrings.

  • Working with document Strings
  • Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f (1, 2) c5>+ g (3, 4).

  • Left and right side of operator, but no space in brackets: a = f (1, 2) + g (3, 4)
  • Name your classes and functions consistently; The Convention is to use CamelCase for classes and Lower_case_with_underscores for functions and methods . Always use self as the name of the first method argument (see A First look at Classes for more on C Lasses and methods).

  • Uniform class name and function name, recommended class name with hump name: SampleClass, function name with lowercase and underscore name: Get_page (), try to use self as the first parameter of the method
  • Don ' t use fancy encodings If your code are meant to being used in international environments. Plain ASCII works best in any case.

  • Use code sparingly in an internationalized environment, with the best ASCII. (in Chinese environment, recommended Utf-8)

Python Coding Style/python Programming 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.