Have you ever read a code you wrote in the past or someone else's code and you were like, hmmmm?
Then, "head scratching" begins...
Lol!...
As a programmer, you'd often do more of reading a code than writing...
Why?
You'd probably visit your code thousands of times in future after writing it for the first time.
So, what made you understand that code?
READABILITY
It's important that you write in such a way others can read, understand and explain your codes.
Remember, companies also hire developers based on how you can collaborate with your colleagues or team.
Here are some python best practices you'd want to consider now!
Type | Style | Example |
Variables | Lowercase letters/word(s) separated by underscores | city, city_names |
Functions | Lowercase letters with words separated by underscores | function, user_input |
Class | Use camel casing style(capitalize every word)...Don't separate the words with an underscore | MyPerson, GardenClub |
Methods | Lowercase letters separated by underscores | methods, method_notes |
Constant | Uppercase letters separated BY underscores | CONSTANT, CONSTANT_PI |
Package | Lowercase letters and not separated by underscores | commerce, mycommerce |
Feel surprised?
I also felt the same way after reading these rules...My advice to you is to start applying those rules in your next python project.
After writing your codes, edit with the rules and you can also check the PEP-8 python documentation PEP-8 DOCS
There are still tons of python best practices to adhere to and I'll discuss more in future.
see you soon!
#python #pythonbestpractices #pep8