Python Interview Questions and Answers

Core language, data structures, comprehensions, decorators and async programming.

Practise 10 random 11 peer-reviewed questions
Python Interview Syllabus & Preparation Strategy

Whether you are preparing for entry-level Python interview questions for freshers or senior software engineer interview questions addressing concurrency, scalability, and system architecture, this track provides peer-reviewed model answers with syntax walkthroughs, edge cases, and practical interview tips.

1 What is the GIL and how does it affect concurrency? Hard

The Global Interpreter Lock is a mutex in CPython that allows only one thread to execute Python bytecode at a time. Consequences:

  • CPU-bound multithreading does not get true parallelism; use multiprocessing or native extensions (NumPy releases the GIL during heavy computation).
  • I/O-bound multithreading and asyncio work well because the GIL is released while waiting on I/O.
  • The GIL simplifies memory management (reference counting) and C extension authoring.

For CPU-bound work: multiprocessing, concurrent.futures.ProcessPoolExecutor, or libraries like NumPy/Cython. Python 3.13+ offers an experimental free-threaded build (PEP 703) that removes the GIL.

2 How does Python memory management work? Hard

CPython combines:

  • Reference counting for immediate reclamation. Every object tracks how many references point to it; when the count hits zero it is freed.
  • A cyclic garbage collector (generational, gc module) to collect reference cycles that counting cannot handle.
  • Private heaps and freelists per object type for fast allocation, plus pymalloc for small objects.

Interview extras: __del__ finalisers, weak references (weakref) to avoid keeping objects alive, and context managers to release resources deterministically with __enter__/__exit__ rather than relying on the GC.

3 What is GIL? What does it do?Talk to me about the GIL. How does it impact concurrency in Python? What kinds of applications does it impact more than others? Hard

Python's GIL is intended to serialize access to interpreter internals from different
threads. On multi­core systems, it means that multiple threads can't effectively make
use of multiple cores. (If the GIL didn't lead to this problem, most people wouldn't care
about the GIL ­ it's only being raised as an issue because of the increasing prevalence
of multi­core systems.)
Note that Python's GIL is only really an issue for CPython, the reference
implementation. Jython and IronPython don't have a GIL. As a Python developer, you
don't generally come across the GIL unless you're writing a C extension. C extension
writers need to release the GIL when their extensions do blocking I/O, so that other
threads in the Python process get a chance to run.

4 Mention at least 3-4 benefits of using Python over the other scripting languages such as Javascript. Hard

Enlisted below are some of the benefits of using Python.

Application development is faster and easy.
Extensive support of modules for any kind of application development including data analytics/machine learning/math-intensive applications.
An excellent support community to get your answers.

5 Which Package Is The Fastest Form Of Python? Hard

PyPy provides maximum compatibility while utilizing CPython implementation for improving its performance.

The tests confirmed that PyPy is nearly five times faster than the CPython. It currently supports Python 2.7.

6 What Is GIL In Python Language? Hard

Python supports GIL (the global interpreter lock) which is a mutex used to secure access to Python objects, synchronizing multiple threads from running the Python bytecodes at the same time.

7 Is there a way to remove the last object from a list? Hard

Yes, there is. Try running the following piece of code-

>>> list=[1,2,3,4,5

>>> list.pop(–1)
5

>>> list

[1, 2, 3, 4]

8 Explain the uses of the modules sqlite3, ctypes, pickle, traceback, and itertools. Hard

sqlite3- Helps with handling databases of type SQLite
ctypes- Lets create and manipulate C data types in Python
pickle- Lets put any data structure to external files
traceback- Allows extraction, formatting, and printing of stack traces
itertools– Supports working with permutations, combinations, and other useful iterables.

9 What are metaclasses in Python? Hard

A metaclass is the class of a class. A class def ines how an instance of the class (i.e. an object) behaves while a metaclass def ines how a class behaves. A class is an instance of a metaclass. You can call it a 'class factory'.

10 What is GIL? Hard

Python has a construct called the Global Interpreter Lock (GIL). The GIL makes sure that only one of your 'threads' can execute at any one time. A thread acquires the GIL, does a little work, then passes the GIL onto the next thread. This happens very quickly so to the human eye it may seem like your threads are executing in parallel, but they are really just taking turns using the same CPU core. All this GIL passing adds overhead to execution.

11 Why Python (CPython and others) uses the GIL? Hard

In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native threads from executing Python bytecodes at once. This lock is necessary mainly because CPython's memory management is not thread-safe.

Python has a GIL as opposed to fine-grained locking for several reasons:

It is faster in the single-threaded case.
It is faster in the multi-threaded case for i/o bound programs.
It is faster in the multi-threaded case for cpu-bound programs that do their compute-intensive work in C libraries.
It makes C extensions easier to write: there will be no switch of Python threads except where you allow it to happen (i.e. between the Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS macros).
It makes wrapping C libraries easier. You don't have to worry about thread-safety. If the library is not thread-safe, you simply keep the GIL locked while you call it

Frequently Asked Questions About Python Interviews

What do hiring managers evaluate in Python technical rounds?

Technical interviewers look for foundational fluency, idiomatic syntax, clarity when communicating complex logic, and awareness of performance trade-offs (e.g. memory footprint, render performance, and network latency) in production environments.

What are the best interview tips for practicing Python questions?

Use active recall: summarize each answer in your own words before revealing the model solution. Focus on explaining why a certain approach is chosen rather than just memorizing code syntax.