Python Naming conventions

Source: Internet
Author: User

Google Open source project style guide: http://zh-google-styleguide.readthedocs.io/en/latest/reference: http://www.cnblogs.com/zhanglianbo/p/ 5664997.html naming

Module_name, Package_name, ClassName, Method_name, Exceptionname, Function_name, Global_var_name, Instance_var_name, Function_parameter_name, Local_var_name.

Names that should be avoided

  1. Single-character names, in addition to counters and iterators.
  2. Hyphen (-) in Package/module name
  3. A name that begins and ends with a double underscore (python reserved, for example __init__)

Naming conventions

  1. The so-called "internal (Internal)" means that only modules are available within the module, or that they are protected or private within the class.
  2. Starting with a single underscore (_) indicates that a module variable or function is protected (not included when using import * from).
  3. An instance variable or method that begins with a double underscore (__) represents a private in-class.
  4. Place related classes and top-level functions in the same module. Unlike Java, there is no need to restrict a module to a class.
  5. Words that begin with a capital letter for the class name (such as capwords, Pascal style), but the module name should be underlined in lowercase (such as lower_with_under.py). Although there are already many existing modules that use a name similar to capwords.py, it is now discouraged because if the module name happens to coincide with the class name, it can be confusing.

Python's father Guido recommended specification

Public
Type Internal
Modules Lower_with_under _lower_with_under
Packages Lower_with_under
Classes Capwords _capwords
Exceptions Capwords
Functions Lower_with_under () _lower_with_under ()
Global/class Constants Caps_with_under _caps_with_under
Global/class Variables Lower_with_under _lower_with_under
Instance Variables Lower_with_under _lower_with_under (Protected) or __lower_with_under (private)
Method Names Lower_with_under () _lower_with_under () (protected) or __lower_with_under (private)
Function/method Parameters Lower_with_under
Local Variables Lower_with_under

Python Naming conventions

Related Article

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.