Coding Standards - Jaber-Al-Siam/Online_Courier_Service_Management GitHub Wiki

Python Coding Standards

Naming Conventions

Variable Name:

The variable name should be in lower case. For multiple word variables, the name should be in lower case with underscores.

Example:

  • football_team
  • customer_address
  • company_name

For Boolean type variable, the name should start with is/has/have. If it’s not necessary, then a general naming convention can be used.

Example:

  • is_male = True
  • is_prime = False
  • if_valid = True

Constants Name:

Constants are usually defined on a module level and written in all capital letters with underscores separating words.

Example:

  • MAX_SIZE
  • TOTAL_STUDENT
  • MOD_VALUE

Method Name:

Method name should be written in lower case letters. For multiple word variables, the name should be in lower case with underscores.

Example:

def function_name():

....print("Hello World")

Package and Module Names:

Package or module name should be written in lower case letters and short. For multiple word variables, the name should be in lower case with underscores.

Example:

  • module_name
  • mobile_name
  • component_list

Class Name:

Class names should be written in the Pascal Casing convention.

Example:

  • class ClassName
  • class Main
  • class Customer

Exception Names:

Because all the exceptions should be classes, the class naming convention applies here. However, one should use the suffix “Error” while writing exception names if the exception is an error.

Example:

  • AssertionError
  • NullPointerError
  • TransactionError

Indentation:

Use 4 spaces per indentation level.

Example:

if (first_condition and second_condition):
....executing_statement ()