Python code specification and naming conventions

Source: Internet
Author: User

1. Module

    • The module uses lowercase names as much as possible, keeping the first letter lowercase and trying not to underline (unless there are multiple words and a small number of cases)
# 正确的模块名import decoderimport html_parser# 不推荐的模块名import Decoder

2. Class name

    • The class name uses the Hump (CamelCase) naming style, capitalized, and the private class can start with an underscore
class Farm(): passclass AnimalFarm(Farm): passclass _PrivateFarm(Farm): pass
    • Place related classes and top-level functions in the same module. Unlike Java, there is no need to restrict a module to a class.

3. Functions

    • Function names are lowercase, if there are multiple words, separated by underscores
def run(): passdef run_with_env(): pass
    • The private function adds an underscore before the function _
class Person(): def _private_func(): pass

4. Variable name

    • Variable names are as lowercase as possible, with multiple words, separated by underscores
if __name__ == ‘__main__‘: count = 0 school_name = ‘‘
    • Constants are all uppercase, if there are multiple words, separated by underscores
MAX_CLIENT = 100MAX_CONNECTION = 1000CONNECTION_TIMEOUT = 600

5. Constants

    • Constants are named with an underscore-delimited capitalization
Max_overflow=  -Class FooBar:   def   foo_bar( Self  ,   print_):   print (   Print_)



Python code specification and 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.