Python has "PEP8: Python Code Style Guide", which also describes naming conventions such as variable names and function names. By matching the naming convention and coding style, you can reduce the burden on those who read the source code and those who review it. Please refer not only to the naming convention but also to the naming method described in "[Readable Code](https://qiita.com/search?q=tag%3A Readable Code)".
PEP8
Use | Naming convention |
---|---|
Private, private | Add one underscore at the beginning |
Avoid name collisions in subclasses | Add two underscores at the beginning |
Special properties, special methods | Add two underscores before and after (Because it is prepared in the language specification, do not define it yourself) |
Avoid conflicts with reserved words and built-in function names | Add one underscore at the end |
Use | Naming convention |
---|---|
package | Short names in all lowercase, no underscores |
module | Short names, all lowercase, may be separated by underscores |
Class, exception | CapWords method (connect uppercase words only at the beginning, do not use underscores) |
Functions, methods | Only lowercase letters, separate words with underscores as needed |
constant | Uppercase only, words separated by underscore |
variable | Only lowercase letters, separate words with underscores as needed |
1 character variable | l (Lowercase el)、O (Uppercase O)、I (Uppercase eye)Never use(Numbers depending on the font 1 、0 Because it is indistinguishable) |
Use | Naming convention |
---|---|
Discard variable | 1 underscore (When variables are required for for loops and split assignments but not used) |
Such.
Recommended Posts