Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Write Better Python Cleaner Code PEP 8

I've seen plenty of people using Python use camelCase, but should you use snake_case?

I am starting to like camelCase (with the very first letter lowercased) more then snake_case because it's faster to type. However, Kenneth Love says that it's better to use snake_case for variable names, function names, file names, etc. and CamelCase (with first letter uppercased) for class names.

Should I use camelCase instead of snake_case? Is this conventional or is it up to you to choose?

Any help appreciated.

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Straight from the creators of Python, naming conventions. You should only use StudlyCaps for class names. Constants should be IN_ALL_CAPS with underscores separating words. Variable, method, and function names should always be snake_case (wonder where it got that name?). You'll see camelCase in some really old Python code but it's not the modern convention at all.

Write your code according to the conventions so other Python developers will know what kind of construct they're dealing with when reading your code. Your code will also fit in better with open source projects or companies that work you with.

OK thanks! I'll stick with snake_case.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

No, stick with what's appropriate for the type of name :D

If it's a class, use StudlyCaps. If it's a constant, use ALL_CAPS. Etc etc.

That's basically what I meant :laughing: