DEV Community

Cover image for šŸ 5 Python Mistakes Every Junior Dev Makes (And How to Fix Them)
Neha Christina
Neha Christina

Posted on

šŸ 5 Python Mistakes Every Junior Dev Makes (And How to Fix Them)

Introduction

If you're a junior developer writing Python, chances are you've made at least one of these mistakes — and you didn't even know it. These aren't syntax errors that your IDE catches. They're subtle bugs and bad habits that slip through code reviews and slow down your growth.
Let's fix all five.

Mistake #1: Mutable Default Arguments

The problem:

def add_item(item, lst=[]):
    lst.append(item)
    return lst
Enter fullscreen mode Exit fullscreen mode

This looks harmless, but Python creates the default list once at function definition — not on every call. So every call shares the same list.

The fix:

def add_item(item, lst=None):
    if lst is None:
        lst = []
    lst.append(item)
    return lst
Enter fullscreen mode Exit fullscreen mode

Always use None as your default for mutable arguments, then create the object inside the function.

Mistake #2: Skipping List Comprehensions

The problem:

squares = []
for i in range(10):
    squares.append(i ** 2)
Enter fullscreen mode Exit fullscreen mode

The fix:

squares = [i ** 2 for i in range(10)]
Enter fullscreen mode Exit fullscreen mode

Cleaner, faster, and more Pythonic. Senior devs will notice immediately.

Mistake #3: Bare Exception Catching

The problem:

try:
    result = 10 / 0
except:
    pass
Enter fullscreen mode Exit fullscreen mode

A bare except catches everything — including KeyboardInterrupt and SystemExit. This makes bugs invisible and debugging a nightmare.

The fix:

try:
    result = 10 / 0
except ZeroDivisionError as e:
    print(f"Error: {e}")
Enter fullscreen mode Exit fullscreen mode

Always catch specific exceptions.

Mistake #4: String Concatenation in Loops

The problem:

result = ""
for word in words:
    result += word
Enter fullscreen mode Exit fullscreen mode

Each += creates a brand new string object in memory. In a loop, that's O(n²).

The fix:

result = "".join(words)
Enter fullscreen mode Exit fullscreen mode

.join() is O(n) and the idiomatic Python way to build strings from iterables.

Mistake #5: Not Using enumerate()

The problem:

for i in range(len(fruits)):
    print(i, fruits[I])
Enter fullscreen mode Exit fullscreen mode

The fix:

for i, fruit in enumerate(fruits):
    print(i, fruit)
Enter fullscreen mode Exit fullscreen mode

enumerate() exists exactly for this. Use it — it's cleaner and avoids off-by-one errors.

Which one were you guilty of? Drop a comment below šŸ‘‡
Follow me on Instagram https://instagram.com/techqueen.codes for visual SQL, Python & Snowflake tips every week.

Enjoyed this? Save the visual cheat sheet on Instagram → https://instagram.com/techqueen.codes

Top comments (0)