The goal of this Python 3 naming convention is to reduce the effort needed to read and understand code and variable scope by applying a consistent naming standard.
Good Practice
Avoid Characters I, l Or O
The single characters I
(aka capital letter of i), l
(aka lowercase of L) or O
(aka capital letter of o) should not be used as variable names. These variable names could easily be mistaken as numerals 1
(one) and 0
(zero).
Meaningful Names
To help clearly document what the name is used for, choose meaningful and descriptive names that implies the intent and meaning of the code. Names can contain both letters, numbers and underscores. However, names cannot start with a number. Remember that names are case sensitive.
Variables
Use lower_case_with_underscores for naming variables, e.g. variable_name
.
MCR Style Configuration Example
variable_name
Constants
Use UPPER_CASE_WITH_UNDERSCORES for naming constants, e.g. CONSTANT_NAME
.
MCR Style Configuration Example
CONSTANT_NAME
Functions
Use lower_case_with_underscores for naming functions, e.g. function_name()
.
MCR Style Configuration Example
function_name()
Classes
Use UpperCamelCase (CapWords) for naming classes, e.g. ClassName
. Capitalize all the letters of abbreviations, e.g. HTTPError
.
MCR Style Configuration Example
ClassName
Reserved Keywords
Listed keywords (aka identifiers) below are reserved by Python 3 and must not be used when choosing names:
False
None
True
and
as
assert
break
class
continue
def
del
elif
else
except
finally
for
from
global
if
import
in
is
lambda
nonlocal
not
or
pass
raise
return
try
while
with
yield
Python Code Example
Try code example below to view a list of all Python 3 keywords:
import keyword
print(keyword.kwlist)