From Junior to Senior: 9 Python Habits That Changed Everything for Me

These 9 habits transformed the way I write Python — and helped me grow from a junior to a senior developer.

From Junior to Senior: 9 Python Habits That Changed Everything for Me
Photo by Aaron Burden on Unsplash

Level up your Python game!

From Junior to Senior: 9 Python Habits That Changed Everything for Me

When I first started writing Python, I thought I was doing pretty well. My scripts worked, they passed the tests (most of the time), and I was writing more lines of code than ever before. But something always felt… off.

It wasn’t until I began working alongside more experienced developers that I realized how much more elegant, efficient, and Pythonic my code could be. Over the years, I picked up habits — some subtle, others transformative — that took me from “just getting it to run” to writing code that was cleaner, faster, and more maintainable.
Here are 9 Python habits that genuinely changed everything for me.

1. Using List Comprehensions Like a Pro

I used to write loops for everything.

squares = [] 
for i in range(10): 
    squares.append(i * i)

Then I discovered list comprehensions.

squares = [i * i for i in range(10)]

Cleaner, faster, and easier to read. It wasn’t just about saving lines — it was about expressing intent more clearly. Bonus: I started reaching for dictionary and set comprehensions too. They’re just as powerful.

2. Utilizing Python’s Unpacking Magic

Tuple unpacking seemed like a party trick — until I realized how much it simplified my code.

person = ('Aashish', 25, 'Engineer') 
name, age, profession = person

I also learned tricks like:

head, *middle, tail = [1, 2, 3, 4, 5]

Unpacking improved everything from iterating over dictionaries to cleaner multiple returns.

3. Embracing the Zen of Python

One day, I typed import this in the REPL and saw this:

“Simple is better than complex.”
“Readability counts.”

These weren’t just fun aphorisms — they were guiding principles. When I started writing code that was simple, readable, and explicit, it started feeling like Python was working with me, not against me.

4. Writing Pythonic Conditionals

Early on, I’d write things like:

if len(my_list) > 0:

Now?

if my_list:

Python’s truthy/falsy semantics are elegant. Empty lists, None, zeros—all evaluate to False. Once I started trusting the language more, my conditionals got much cleaner.

5. Using F-Strings for Everything

I clung to .format() and even % formatting longer than I should have. But f-strings? Game changer.

name = 'Aashish' 
age = 25 
print(f"{name} is {age} years old.")

They’re faster, cleaner, and easier to read. Once you go f-string, you never go back.

6. Harnessing Generators and Lazy Evaluation

There was a time when I didn’t know the difference between a list and a generator. Then I learned about memory efficiency and lazy evaluation.

def fibonacci(): 
    a, b = 0, 1 
    while True: 
        yield a 
        a, b = b, a + b

Generators allowed me to handle massive data without blowing up memory. yield became one of my favorite keywords.

7. Being a Dict Ninja

I used to treat dictionaries like basic data holders. Now I use them like Swiss Army knives.

  • .get() to avoid KeyErrors.
  • Dictionary unpacking with **.
  • Using defaultdict for cleaner counters and grouping.
  • Utilizing dict comprehensions.
from collections import defaultdict 
 
grouped = defaultdict(list) 
for item in data: 
    grouped[item.key].append(item)

Dictionaries became not just useful — they became essential.

8. Mastering Context Managers (with)

I thought with open(...) was just for files. Then I realized the context manager pattern is everywhere.

  • Managing locks.
  • Database sessions.
  • Temporary directories.
  • Even creating custom context managers with contextlib.
from contextlib import contextmanager 
 
@contextmanager 
def my_context(): 
    print("Before") 
    yield 
    print("After")

This taught me not just a Python trick — but also a design pattern.

9. Writing Tests Like Documentation

I used to write tests just to appease CI. Now I write them to document behavior and prevent future bugs.

I learned:

  • Use pytest for simple, elegant test syntax.
  • Name tests clearly: test_user_cannot_login_with_invalid_password().
  • Write fixtures for setup.
  • Test edge cases.

Good tests gave me confidence to refactor fearlessly. That’s a superpower.


Final Thoughts

Going from junior to senior in Python wasn’t about learning the fanciest libraries or mastering obscure syntax. It was about learning to think Pythonically. To write code that communicates, not just executes.

If you’re early in your journey, don’t stress. These habits don’t form overnight. But as you write more, read more, and refactor more — you’ll find your own rhythm.

And when you do, you’ll feel it: the shift from writing code that works to writing code you’re proud of.

Happy coding

If this resonated with you, feel free to follow or leave a comment! I love swapping Python tips and hearing how others leveled up.

Photo by Thalia Tran on Unsplash