Python Tip #84 (of 365):

Use variables to improve code clarity.

Today's tip is the inverse of yesterday's tip.

Well-named variables CAN make your code more readable and they don't really make your code less efficient (after all, variables are just pointers).

๐Ÿงต (1/2)

#Python #DailyPythonTip

For example, it may not be clear what this condition checks:

if len(text) - len(text.lstrip()) >= 4:
...

But it's pretty clear what this one checks:

indent_level = len(text) - len(text.lstrip())
if indent_level >= 4:
...

Even if a variable is strictly unnecessary, if it improves readability you should keep it!

๐Ÿงต (2/2)