r/learnpython • u/HelloWorldMisericord • Mar 25 '25
TIL Python recommends you use snake_case instead of camelCase for variables
Apologies if this is a "low quality" post or something frequently brought up, but thought I'd share in the spirit of shared learning.
I started off programming in VB, Java, C++ and the convention I was taught/saw everyone using was camelCase.
As I've dipped my toe further into Python and started looking into the actual code of my favorite libraries on Github, I noticed that they were all using snake_case whenever possible. Upon further research, it seems PEP8 advocates for snake_case (unless for backward compatability).
I'm sure smarter people than me have argued over which is more readable (snake_case vs camelCase) so I won't chime in on this. To me, this is just a convention and it's more important to pick whatever works best for your purposes (i.e. if you're going to be contributing to open source Python projects, maybe stick with snake_case).
In the same vein, I also have been reading a bit about spaces between equal signs and variables in declarations vs use in arguments suffice to say that is a separate topics.
10
u/artibyrd Mar 25 '25
They're more like guidelines than actual rules. The PEP 8 style guide even says: "Many projects have their own coding style guidelines. In the event of any conflicts, such project-specific guides take precedence for that project." The PEP 8 guidelines document the coding conventions used by Python itself in the standard library, but you can choose to do your own thing if you have reasons or opinions to do otherwise in your own project. If you find camelCase more readable due to other programming experience, nothing is stopping you from using it.
6
u/nog642 Mar 25 '25
Having an official language style guide is very convenient. Makes Python code more consistent and easier to read when it's mostly followed.
It's not gospel though. That 79 character limit for lines is kinda ridiculous.
4
u/ben_bliksem Mar 25 '25
Variety (in language conventions) is the spice of life.
4
u/_Acolyte_ Mar 25 '25
It’s only low quality because you diluted your message by posting the same thing three times.
2
u/FantasticEmu Mar 25 '25
I mean it’s python it makes sense to be snek right? Jk idk how anyone decides this I just name my variable a b c d… so I don’t have to worry about it!
Nothing of value was added by this comment
13
u/[deleted] Mar 25 '25 edited Mar 25 '25
[removed] — view removed comment