Python Interview Questions

Frequently asked Python interview questions for backend, data, and general software roles — from the GIL and decorators to generators and memory — with clear answers. Then rehearse them in a live mock.

Practice these live with an AI interviewer
Get asked questions one at a time and a scored feedback report — free.

10 common Python questions

What are Python's core built-in data structures?

list (ordered, mutable), tuple (ordered, immutable), dict (key-value mapping), and set (unique, unordered). Choose based on whether you need mutability, ordering, or fast membership tests.

list versus tuple?

Lists are mutable — you can append and change them. Tuples are immutable and hashable, so they can be dict keys, are slightly faster, and signal that the data is fixed.

What is a list comprehension?

A concise way to build a list, like [x*2 for x in items if x > 0]. It's usually more readable and a bit faster than the equivalent for-loop with append.

Explain *args and **kwargs.

*args collects extra positional arguments into a tuple and **kwargs collects extra keyword arguments into a dict. They let a function accept a flexible number of arguments.

What is the GIL?

The Global Interpreter Lock allows only one thread to execute Python bytecode at a time, so threads don't speed up CPU-bound work. Use multiprocessing, async, or C extensions for real parallelism.

is versus ==?

== compares values, while is compares identity — whether two names point to the same object in memory. Use is only for singletons like None.

What are decorators?

Decorators are functions that wrap another function to add behavior — logging, timing, caching, auth — without changing it, applied with @decorator syntax. A decorator takes a function and returns a new one.

Explain generators and yield.

Generators produce values lazily, one at a time, using yield and keeping their state between calls. They're memory-efficient for large or streaming sequences because they don't build the whole result at once.

How does Python manage memory?

Through reference counting plus a cyclic garbage collector. An object is freed when its reference count hits zero, and the collector reclaims objects trapped in reference cycles.

What is a context manager (the with statement)?

An object with __enter__ and __exit__ methods that handles setup and teardown automatically — like closing a file or releasing a lock — even if an exception occurs inside the block.

Ready to practice out loud?

Reading answers is one thing — saying them under pressure is another. Run a free AI mock interview and get scored feedback.

Start a mock interview

More interview questions