I have been long puzzled about this question, whether Python is an interpretive language or compiled one. I was told that it is an interpretive language. But again a question raises that, if it is not compiled then what stuff, is that, a file named with an extension of .pyc.
Hence, as a result of a little surfing, I am on a conclusion as mentioned below.

An interpretive language:

Python is basically an interpreted language.

An interpreted language is one, in which, the translation of high level Source Code to low level Machine code is done by an interpreter, a kind of translator. The interpreter reads the source code line by line, and executes it along the way.

It does not convert it into any object code that can be saved on disc, i.e. you can write the source code and save it as a script. Then when you run the code, the interpreter goes through each line and converts the code to machine understandable code and executes it. As we should notice, the code is not saved as a converted machine code; it is just dynamically converted to get executed. This is one of the reasons, why Python is called Dynamic programming language. In this way, the code is still just source code, even after the execution. Now, when you run the code again, the same procedure follows. One reason, why Python is slow.

Now, what is “.pyc” then?

For that let’s look at a term called, “Byte code”.

Byte Code:

In between, the concept of interpreted and Compiled paradigms, there come the concept of portable compiled languages. In these, the Source Code is converted to byte code, and the python interpreter then executes the byte code line by line, converting it to machine code.

So, byte code is a converted form of source code, which is faster in later conversion to machine code. Unlike source code, byte codes are compact numeric codes, constants, and references (normally numeric addresses) which parse the Semantics of a program object and encode it, resulting in better performance than direct interpretation of source code. A point to be marked here is that, the byte code itself can’t be directly executed by the machine. It again needs interpreter for execution. In this way, the execution is faster than source execution only and not compiled.


Now, a PYC (PYthon Cached) file is just the byte code of a script written in Python. It comes in existence, when we import the .py file as a module in another script or in interactive shell of Python. When a module is imported, the script needs to interpret the module file also. Since these modules undergo repeated use, the interpreter converts their source code into byte code and stores that into a file named with extension ‘.pyc’. In this way, when a script imports that module, the byte code version already exists, ready and fast to use. Furthermore, these modules become portable across multiple platforms.

Hence, the pyc file is not a compiled file, as it is not able to execute directly. It is just a conversion of source into byte code, so that the execution is less overhead as the interpreter needs fewer conversions to perform.


This thread was also helpful,Alex Martelli’s, and Jorg W Mittag's answer :