Python Interview Questions
Practice Python questions covering data structures, decorators, generators, comprehensions, and Pythonic programming patterns.
Frequently Asked Questions
What Python topics are commonly tested in interviews?
Built-in data structures (lists, dicts, sets, tuples), list comprehensions, generators, decorators, context managers, OOP in Python, exception handling, and the standard library (collections, itertools). For data roles, also know NumPy, Pandas, and basic ML concepts.
Is Python a good language choice for coding interviews?
Python is excellent for interviews. Its concise syntax lets you write solutions quickly, and its rich standard library (collections.Counter, heapq, defaultdict) simplifies many problems. Most FAANG companies accept Python, and it's the most popular choice among candidates.
What are Python decorators and how do they work?
Decorators are functions that modify other functions. They use the @decorator syntax and wrap a function to add behavior before/after it runs. Common uses include logging, timing, authentication, and caching. Understanding closures is key to understanding decorators.
What is the difference between a list and a tuple?
Lists are mutable (can be modified after creation) while tuples are immutable. Tuples are slightly faster and can be used as dictionary keys. Use tuples for fixed data like coordinates or database rows, and lists when you need to add, remove, or modify elements.
How do generators work in Python?
Generators are functions that use yield instead of return, producing values one at a time lazily. They save memory by not storing the entire sequence. Generator expressions (x for x in range(n)) are the expression form. They are ideal for processing large datasets or infinite sequences.
What is the GIL and how does it affect Python?
The Global Interpreter Lock (GIL) in CPython prevents true parallel execution of Python bytecode across threads. CPU-bound tasks should use multiprocessing instead of threading. I/O-bound tasks (network, file) still benefit from threading because the GIL is released during I/O operations.