Introduction
PEP8 was designed to make Python code more readable. If you’re new to Python, remembering what a piece of code does a few days or weeks after you created it can be challenging. If you follow PEP8, you may be able to assure that your variables have been properly named.
Naming Conventions Styles
Type | Naming Convention | Examples |
---|---|---|
Function | Lowercase and underscores | function(), my_function() |
Variable | Lowercase and underscores | x, var, my_variable |
Class | Start with uppercase and without underscores | Model, MyClass |
Method | Lowercase and underscores | class_method(), method() |
Constant | Uppercase only and separate with underscores | CONSTANT, MY_CONSTANT |
Module | Lowercase and underscores | module.py, my_module.py |
Package | Lowercase only | package, mypackage |
Conclusions
Choosing names for variables, functions, classes, and other objects can be difficult. When writing code, you should give some care to your name choices because it will make your code more reasonable and readable. Using descriptive names to make it obvious what the object represents is the best technique to name your objects in Python. Cheers and sounds!