See Python PEP 8: Function and Variable Names:
Answer from S.Lott on Stack OverflowFunction names should be lowercase, with words separated by underscores as necessary to improve readability.
Variable names follow the same convention as function names.
mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.
-
We have to agree that variables names are an essential part of the source code and meaningful names are important when it comes to program comprehension.
-
They serve as an implied documentation that should convey to the reader;
-
Considering that sometimes names are the only documentation, then clean code approach should be highly regarded.
-
Therefore, it is important to devote a considerable amount of time to the issue of variable naming and therefore the variable names and rules.
Variable Names Rules & Guidelines
-
A variable name CAN be one word, though not a Must
-
You SHOULD separate words with underscores and not spaces.
-
When naming variable's we SHOULD only use alpha-numeric characters (letters and numbers) and the underscore character.
-
You SHOULD NOT start a variable name with a number, but can start with a letter or an underscore character. Breaking this rule will give you an invalid decimal literal or syntax error
-
A variable name SHOULD start with a letter or the underscore character.
-
You SHOULD NOT use python keywords and function names as variable names.
-
Variable names are case sensitive message, Message, MESSAGE and MeSsAge are different
-
Ensure that variable names are; Short: though they can be long. Descriptive: That is can tell what the variable is used for.
-
Take note that some letters like lowercase l and uppercase letter O can easily be confused with number 1 and 0.
-
While it is legal to use upper case letters; Others think it is a good idea to start variable names with lower case letter. Others believe that they better use camel case than separate names with_ . Others avoid starting variables names with an underscore, unless when they are writing library code.
References and further reading.
Watch this for code examples
What is the naming convention in Python for variables and functions? - Stack Overflow
Best practices for naming variables: what the research shows
Are underscored variable naming convention used commonly in industry?
Go to variable names?
Videos
See Python PEP 8: Function and Variable Names:
Function names should be lowercase, with words separated by underscores as necessary to improve readability.
Variable names follow the same convention as function names.
mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.
The Google Python Style Guide has the following convention:
module_name,package_name,ClassName,method_name,ExceptionName,function_name,GLOBAL_CONSTANT_NAME,global_var_name,instance_var_name,function_parameter_name,local_var_name.
A similar naming scheme should be applied to a CLASS_CONSTANT_NAME