The best way to name your objects in Python is to use descriptive names to make it clear what the object represents.
When naming variables, you may be tempted to choose simple, single-letter lowercase names, like x. But, unless you’re using x as the argument of a mathematical function, it’s not clear what x represents. Imagine you are storing a person’s name as a string, and you want to use string slicing to format their name differently. You could end up with something like this:
It seems natural to use the variables that we are used to in formulas, but we have to be careful to avoid l, O, and I. For example:
Both of the above examples run the same but the second one is easier for a human to detect what the variables are.
Consider the following function that calculates area of a rectangle:
ar is not a very descriptive function name. Here's a better way:
Even though I abbreviated rectangle to rect, area_rect gives me a better idea of what the function does than ar.