Hello there, good question.
Yes, Python does have some pretty standard naming conventions, and following them makes your code way easier to read (especially when you come back to it later).
Use clear, specific names
Good:
favorite_food,total_price,student_countNot so good:
x,temp,data(unless it truly is temporary or generic)
Use snake_case for variables
Python style is lowercase words separated by underscores (known as snake_case):
favorite_foodinstead offavoriteFood
Donāt use Python keywords
You canāt name variables things like
class,def,if,for, etc.If you really need something close, people often do:
class_(with an underscore at the end)
Be consistent with casing
Python treats
score,Score, andSCOREas different names.Most variables stay lowercase:
score,high_score,max_score
Special naming patterns youāll see a lot
Constants (values you donāt plan to change):
MAX_SPEED,PI,TAX_RATEāPrivateā / internal use (a hint to other programmers):
_hidden_valueAvoid names that look like built-ins: donāt name a variable
list,str, orsum(youāll overwrite the built-in function by accident)
If you stick to descriptive names + snake_case, your code will instantly look more professional and be easier to understand.
Feel free to reach out if you have any questions.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer
