What is the appropriate style to write in Python?

Asked

Viewed 48 times

1

What standard to name classes, methods, variables, etc., in Python, I thought just like in Java was Camelcase, but recently I heard to use snake_case. Is there any specific Python pattern? Which of these two is best to use?

1 answer

3


That’s documenting in PEP8. Basically says to use the pattern snake_case, that is, write everything in lowercase and words are separated with a underline.

This applies to almost all identifiers, except constants suggested to use ALL_CAPS, that only changes that everything is uppercase. And class names should follow the style PascalCase, so all words should just start with uppercase, the rest is lowercase. It seems that exceptions as well, but then we enter google guide.

Not everyone follows the official recommendation. The most important thing is to be consistent after you choose but if the language has chosen one way if you choose another it will start to appear inconsistencies. There are people who might think it’s good to indicate better what your code is, but I don’t think it’s good.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.