Member-only story
9 Python Errors That Signal You’re Still a Beginner.
Python is popular, but even experts make mistakes. Here are 9 common Python errors, explained with examples, to help new coders

- Pythonic Idioms Ignored:
- Wrong: Looping with
for
to create a list.
squares = []
for i in range(5): squares.append(i**2)
- Right: Embrace Pythonic list comprehensions.
squares = [i**2 for i in range(5)]
2. Mutable Defaults Misused:
- Wrong: Default list in function arguments.
def add_item(item, list=[]): list.append(item)
- Right: Use
None
and initialize inside.
def add_item(item, list=None):
if list is None: list = []
list.append(item)
3. ‘is’ Operator Confusion:
- Wrong: Using ‘is’ for value equality.
if a_list is another_list: ...
- Right: Use ‘==’ for equality checks.
if a_list == another_list: ...
4. Indentation Errors:
- Wrong: Misaligned indentation.
def example():
print("Oops!")
- Right: Correctly indented code.
def example():
print("Correct!")
5. Variable Scope Oversight:
- Wrong: Accessing local variables outside.
def func(): x = 10
print(x)
- Right: Define and return variables appropriately.
def func():
x = 10
return x
print(func())
6. Global Variable Overuse:
- Wrong: Modifying globals inside functions.
x = 5
def change(): x = 10
- Right: Pass and return values.
x = 5
def change(x): return x + 5
x = change(x)
7. Ignoring Exception Handling:
- Wrong: Dividing by zero without handling.
print(10/0)
- Right: Use try-except for error handling.
try:
print(10/0)
except ZeroDivisionError:
print("Can't divide by zero.")