Member-only story
Python Tricks That Make Your Code Look Like You Know What You’re Doing
Before I knew how to write good Python code, I believed that knowing more libraries and learning complex syntax was the key.
However, the more code I have written, the clearer it became to me that what separates functional code from professional is often a matter of minor choices.
Sometimes you do not need to invent a new framework or use some complex approach. Using enumerate() instead of a for-loop that consists of five lines of code, taking advantage of dictionary’s get() method, or unpacking values correctly — these are all examples of changes that can improve your code.
The best thing about these changes is that they are practical and you can immediately apply them in your next Python project while keeping the way you develop applications intact.
Here are seven Python tips that will improve your code quality.
1. Stop Using range(len()) When enumerate() Does the Job
I’ve seen this pattern in plenty of Python code:
languages = ["Python", "JavaScript", "Go"]
for i in range(len(languages)):
print(i, languages[i])It works. But Python gives us a better way to do this.








