问题
I would like to learn aout the naming convetions in this language, this is explained in the official documentation?, if not how I could introduce to good Python practices?
回答1:
As mentioned in the comments, you can reference the official Python style guide here. The naming conventions are here.
You can also check out Google's Python style guide here, with naming conventions addressed here.
Here are some highlights from Google:
Names to avoid
- single character names, except for counters or iterators
- dashes (-) in any package/module name
- __double_leading_and_trailing_underscore__ names (reserved by Python)
Naming convention
Note that some naming conventions differ from PEP8 and instead follow the original Google Python Style guide from which this style guide originated.
"Internal" means internal to a module or protected or private within a class.
Prepending a single underscore (_) has some support for protecting module variables and functions (not included with import * from).
Prepending a double underscore (__) to an instance variable or method effectively serves to make the variable or method private to its class (using name mangling).
Place related classes and top-level functions together in a module. Unlike Java, there is no need to limit yourself to one class per module. However, make sure the classes and top-level functions in the same module have high cohesion.
Use CapWords for class names, but lower_with_under.py for module names. Naming examples
来源:https://stackoverflow.com/questions/27576401/python-naming-conventions-guide