I am currently learning some advanced Python at school, and my teacher has recommended the use of PascalCase for all variable, function, and class names. He says that since all Python keywords are lowercase, this convention will help to differentiate between one's own code and Python built-ins. However, this convention is unlike any other programming language, and I do not know whether it is acceptable to continue in this way. Can I use this convention for personal projects? And change it to a more universal convention when I need to?
Asked
Active
Viewed 1,898 times
0
-
1PEP 8 is the standard python style guide. https://www.python.org/dev/peps/pep-0008/#naming-conventions . I'd stick to following that unless there's a good reason not to (eg: working for a company or on a project which uses a different style). Of course, you're allowed to do whatever you want :) – Paul Hankin Jul 01 '21 at 11:09
-
Does this answer your question? [Should I use “camel case” or underscores in Python?](https://stackoverflow.com/q/8908760/2745495) – Gino Mempin Jul 01 '21 at 11:10
-
Does this answer your question? [How should I name my classes and function and even strings?](https://stackoverflow.com/q/12007811/2745495) – Gino Mempin Jul 01 '21 at 11:16
-
"*And change it to a more universal convention when I need to?*" I would say it is better to adapt and stick to 1 common convention *now*, rather than to be switching *later* or *when you need to*. It would be much less confusing that way. – Gino Mempin Jul 01 '21 at 11:18
1 Answers
1
Your professor is wrong; he goes against the industry standard style guide for Python, PEP-8. In particular, function and variable names should be lowercase, separated by underscores.
Following his advice where not forced to (that is, outside of assignments he grades) might cause you harm if used in a portfolio presented to future employers.

orlp
- 112,504
- 36
- 218
- 315
-
What about camelCase? I have seen numerous examples where this has been used in Python. Or should I just stick with snake_case? – stadepalli Jul 01 '21 at 11:16
-
I completely agree that one should use PEP-8 wherever possible (and it's not just an industry standard -- it's a standard for all python code!). I think the warnings about harm when applying for jobs are overstated though. – Paul Hankin Jul 01 '21 at 11:16
-
1@stadepalli just follow PEP-8. Sure, lots of people and projects have their own ideas, but that's no reason to follow them rather than the standard. – Paul Hankin Jul 01 '21 at 11:18
-
1@PaulHankin It depends on the interviewer–at least to me not following coding standards signifies a lack of attention to detail and would definitely be a point against a candidate. I changed the wording from 'likely' to 'might' though. – orlp Jul 01 '21 at 11:19