[Fixed]-Naming variable, best convention

15👍

10👍

PEP 8, nothing more to say.

Of course you can use your own style (I use camelCase, for example), but most people use recommendations from that PEP.

2👍

Code Complete (http://www.cc2e.com/) has some great chapters about function/variable naming, not for Python explicitly, but perhaps still interesting…

2👍

In addition to the correct references to PEP-8 and Django, let me add Google’s Python style guide, which features a naming convention. It is here.

👤shanyu

1👍

The important thing is being consistent with your naming style. Choose one with your project mates and use it. Don’t mix them. I personally use camelCase:

Sample class name: MyClass (capital letter at the beginning)

Sample method name: myMethod

Sample variable name: myVariable

Sample constant/enum name: MY_CONST

Class name should start with capital letter to make clear what it is in your code. Same about constants/enums. Values that don’t change throughout your program should consist of capital letters.

1👍

I use lower_case_with_underscore for variables, methods and functions. I think it really improves readability of the code.

For classes, I tend to use upper case the first letter: class NewsForm (forms.Form):

👤Rami_H

Leave a comment