Member-only story
9 Confusing Python Concepts That Frustrate Most Developers
3 min readOct 3, 2024
1. The is vs == Confusion
== compares values (equality), while is compares object identities (whether two objects point to the same memory location).
a = [1, 2, 3]
b = [1, 2, 3]
print(a == b)
print(a is b)
True
False
2. Mutable Default Arguments
Using mutable objects (like lists or dictionaries) as default arguments in function definitions leads to unexpected behavior.
def add_element(element, my_list=[]):
my_list.append(element)
return my_list
print(add_element(1))
print(add_element(2))
[1]
[1, 2]
3. Indentation Sensitivity
Python’s strict use of whitespace for block definition can be a challenge for new users. Inconsistent or invisible tabs vs spaces can cause errors.
In [7]:
if True:
print("Hello")
print("World")
Hello
World