02 / 02

Is Python a compiled language or an interpreted language?

Please remember one thing, whether a language is compiled or interpreted or both is not defined in the language standard. In other words, it is not a properly of a programming language. Different Python distributions (or implementations) choose to do different things (compile or interpret or both). However the most common implementations like CPython do both compile and interpret, but in different stages of its execution process.

  1. 1

    Compilation: When you write Python code and run it, the source code (.py files) is first compiled into an intermediate form called bytecode (.pyc files). This bytecode is a lower-level representation of your code, but it is still not directly machine code. It’s something that the Python Virtual Machine (PVM) can understand and execute.

  2. 2

    Interpretation: After Python code is compiled into bytecode, it is executed by the Python Virtual Machine (PVM), which is an interpreter. The PVM reads the bytecode and executes it line-by-line at runtime, which is why Python is considered an interpreted language in practice.

Difficulty: 3/10
Topics: execution model, bytecode, interpreter

Scenario Questions

0-2 years experience
  1. 1

    When you run python script.py on your laptop, walk me through what happens behind the scenes from the moment you hit Enter to the output appearing.

  2. 2

    If you need to ship a small utility to a client machine that doesn't have Python installed, how would you package it and why does Python's execution model matter for that choice?

2-5 years experience
  1. 1

    Your team notices a Python microservice is slower than a similar service written in Go. How would you investigate whether the interpreter overhead is the cause, and what alternatives could you consider?

  2. 2

    A CI build fails with a syntax error on a Linux runner but works locally on macOS. Explain how Python's compilation to bytecode could lead to this discrepancy.

5-8 years experience
  1. 1

    Design a data‑processing pipeline that must handle tens of millions of records per second. Discuss the trade‑offs of keeping the code pure Python versus compiling hot paths with C extensions or using PyPy.

  2. 2

    We need to sandbox untrusted Python code and enforce strict execution time limits. How does Python's interpreted nature affect your strategy compared to a compiled language like Java?

8+ years experience
  1. 1

    Our organization plans to migrate a large legacy Python monolith to a more performant stack. What architectural factors would you evaluate regarding Python's interpreted nature, and where might you introduce compiled components?

  2. 2

    When building a cross‑team library that will be consumed by services written in Python and other languages, how does Python's execution model influence versioning, distribution, and long‑term maintenance decisions?

Follow-up Questions

  • Can you describe a situation where you needed the compiled bytecode?
  • What impact does the interpreter have on startup time?
  • How would you reduce the overhead of interpretation in a performance‑critical path?