So I know some languages have expected conventions.
PHP - underscore_case()
[for the most part, lolo]
Java - camelCase()
C# - PascalCase()
etc.
What's the "Pythonic" naming convention? I know it doesn't matter in the end but just wondering if there is a "best practice" way that most modules are done in.
Two words: PEP 8.
PEP 8 is the (de facto) Python style guide. Some highlights from this document (I left some stuff out on purpose; go read the original document for the ins and outs):
Package and Module Names: All-lowercase names. Underscores can be used in the module name if it improves readability.
Class Names: Almost without exception, class names use the CapWords convention.*
Global Variable Names: The conventions are about the same as those for functions.
Function Names: Function names should be lowercase, with words separated by underscores as necessary to improve readability. mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py
), to retain backwards compatibility.
Method Names and Instance Variables: Lowercase with words separated by underscores as necessary to improve readability. Use one leading underscore only for non-public methods and instance variables.
Constants: Written in all capital letters with underscores separating words. Examples include.
Read PEP 8.
It's a style guide for Python code, written by Python's creator, Guido van Rossum.
Incidentally, the answer to your question is to use underscore_case
for variables and function names, and PascalCase
for classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With