# Is Python a compiled language or an interpreted language?

**URL:** <https://discuss.python.org/t/is-python-a-compiled-language-or-an-interpreted-language/6556>\
**Category:** Python Help\
**Created:** [January 9, 2021, 8:07am UTC](https://discuss.python.org/t/is-python-a-compiled-language-or-an-interpreted-language/6556 "2021-01-09T08:07:54Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [January 9, 2021, 10:52am UTC](https://discuss.python.org/t/is-python-a-compiled-language-or-an-interpreted-language/6556/3 "2021-01-09T10:52:04Z")

</div>

Hi Jhon, you asked:

“is python compiled language or an interpreted language”

Short answer: it is both. It’s an interpreter with a compiler. But if  
you can only give one answer, it is more of an interpreted language than  
a compiled language.

Longer answer:

When people talk about “compiled languages”, they often think about  
languages like C. In C, the process of running a program looks something  
like this (simplified):

- you write the source code;

- you use a _compiler_ which turns your source code into  
_machine language_ that the CPU of your computer understands;

- every different family of CPUs uses a different machine language,  
so computer architectures (e.g. Windows versus Mac) needs a  
different compiler;

- but once you have the compiled machine language, you no longer need  
either the source code or the compiler;

- on the other hand, the compiled code will only run on one family  
of machines, so you need a separate Windows and Mac version of  
your program.

When people talk about “interpreted languages”, they usually are  
thinking of something like this:

- you write the source code;

- you use an _interpreter_ which looks at the source code and  
directly executes the statements, without compiling it to  
machine language first;

- so to run code in an interpreted language, you must have both  
the source code and the interpreter;

- and a single program (the source code) will run on any machine  
with the right interpreter.

Python, like most languages for, oh, about forty years, combines  
elements of both:

- you write the source code;

- when you use the interpreter, it first _compiles_ the source  
code into “byte code”;

- unlike machine code, which is specific to a family of CPUs and  
machine architectures, the byte code is independent of what sort  
of machine you are using;

- the interpreter then has a “virtual machine” which knows how to  
run the byte code; think of it as a simulated CPU;

- like compiled languages, there is an intermediate form (the byte  
code) between what you write (source code) and what gets run by  
the actual CPU;

- so you can compile Python code into a .pyc file and then run that  
compiled version instead of the source code;

- but like interpreted languages, the byte code doesn’t run directly  
on the CPU of your computer; you still need the interpreter to  
run the byte code;

- which means that the same .py or .pyc file can be used on any  
machine that has the right interpreter;

- some Python interpreters, like PyPy, include a “Just In Time”  
compiler which turn parts of the byte-code into machine language  
as needed, for extra speed, without losing the advantages of  
having an interpreter.

These days, most modern languages have elements of both. Interpreters  
nearly always have an intermediate compiled form that runs in a virtual  
machine; compilers sometimes have a built-in interpreter.

---

_[View the full topic](https://discuss.python.org/t/is-python-a-compiled-language-or-an-interpreted-language/6556)._
