4
What is the difference between == and is?
Short Answer
== checks value equality. is checks identity (same object in memory).
a = [1, 2, 3]
b = [1, 2, 3]
print(a == b) # True (same value)
print(a is b) # False (different objects)
# Integer caching (-5 to 256)
x = 256
y = 256
print(x is y) # True (cached!)
💡 Memory Trick: "== asks 'same value?' | is asks 'same place in memory?'"
6
What are Python decorators?
Short Answer
Decorators are functions that modify the behavior of other functions/classes without changing their source code. They use the @ syntax.
def timer(func):
import time
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
print(f"{func.__name__} took {time.time()-start:.4f}s")
return result
return wrapper
@timer
def train_model(epochs):
# training logic
pass 💡 Memory Trick: "Decorator = Wrapper Gift Box — same gift inside, prettier outside"
Follow-up Questions
- What is functools.wraps and why is it important?
- Can you stack multiple decorators?
- What is a class-based decorator?
Questions 7-50 continue with the same detailed format.
Topics covered: Generators, List Comprehensions, GIL, Deep/Shallow Copy, *args/**kwargs, Magic Methods, Lambda, Exception Handling, Context Managers, String Formatting, Namespaces (LEGB), @staticmethod vs @classmethod, and more.
View Full Documentation →