Python Coding Conventions
- Indentation is 4 spaces. Always.
- Variable names and function/method names start with lower-case letters. Then, use camelCase. I.e., subsequent words in the variable name are capitalized.
- Make variable names meaningful, but hopefully not too long.
- Use comments where appropriate to explain a tricky line of code, or to explain a block of code coming up. Prefer comments on their own line instead of comments to the right of code.
- Keep lines short -- 79 characters or less is best. This is not a hard and fast rule, but something to strive for.
- Use a space around operators: e.g.,
|x == 3
|x * math.pi / r
|abc = 7 * x
- Don't put a space before the left parenthesis in a method/function call:
Good: result = sqrt(x) Bad: result = sqrt (x)
This page maintained by Victor Norman .