10 Python Interview Questions for Senior Developers

Dive into the internals

Yang Zhou
TechToFreedom

--

Landscape drawing
Image from Wallhaven

Python is easy to learn, but hard to master.

You may learn its basic syntax in a few days. But to be capable of developing good-enough commercial software in Python, many years of practice is inevitable.

Because, no matter which programming language you’re using, you have to know enough about its complex internal mechanisms to build something robust.

This article will show you 10 Python interview questions for senior developers. They are not something like “how to write a loop in Python”. They are aiming to test the interviewee’s deep understanding of the Python internals.

1. Integer Caching Mechanism in Python

Interviewer:

Please explain the following results of the code executed on a Python shell interpreter:

>>> a=256
>>> b=256
>>> a is b
True
>>> x=257
>>> y=257
>>> x is y
False

Answer:

This is because of the integer caching mechanism in Python. To save time and memory costs, Python always pre-loads all the small integers in the range of [-5, 256].

Therefore, all the integers in [-5, 256] have been already saved in the memory. When a

--

--