Code Conventions

Python Naming Conventions

 

1. Packages

  • Package names should be all lower case.
  • When multiple words are needed, an underscore should separate them.

2. Modules

  • Module names should be all lower case.
  • When multiple words are needed, an underscore should separate them.

3. Classes

  • Class names should follow the UpperCaseCamelCase convention.
  • Python built-in classes, however are typically lowercase words.

4. Global Variables

  • Global variables should be all lowercase.
  • Words in a global variable name should be separated by an underscore.

5. Instance Variables

  • Instance variable names should be all lower case.
  • Words in an instance variable name should be separated by an underscore.
  • Non-public instance variables should begin with a single underscore.
  • If an instance name needs to be mangled, two underscores may begin its name.

6. Methods

  • Method names should be all lower case.
  • Words in an method name should be separated by an underscore.
  • Non-public method should begin with a single underscore.
  • If a method name needs to be mangled, two underscores may begin its name.

7. Method Arguments

  • Instance methods should have their first argument named ‘self’.
  • Class methods should have their first argument named ‘cls’.

8. Functions

  • Function names should be all lower case.
  • Words in a function name should be separated by an underscore.

9. Constants

  • Constant names must be fully capitalized.
  • Words in a constant name should be separated by an underscore. 

Examples :- 

VARIABLE ------------------  variable_name

CONSTANT VARIABLE -------- VARIABLE_NAME

FUNCTIONS ----------------------- functionname()

CLASS ------------------------------- ClassName

METHOD --------------------------- methodName() --CAMEL CASE

MODULES -------------------------- modulename

PACKAGE -------------------------- packagename

 

Comment :-

#This is Single line Comment.

-----------------------------------------------------------------------

"

This

      is

        multiline

                Comment

"

 

"""

This 

     is 

        also a

           Multiline

                 Comment

"""

 

Comments