Python | Compiled or Interpreted ?

In various books of python programming, it is mentioned that python language is interpreted. But that is half correct the python program is first compiled and then interpreted. The compilation part is hidden from the programmer thus, many programmers believe that it is an interpreted language. The compilation part is done first when we execute our code and this will generate byte code and internally this byte code gets converted by the python virtual machine(p.v.m) according to the underlying platform(machine+operating system).
Now the question is – if there is any proof that python first compiles the program internally and then run the code via interpreter?
The answer is yes! and note this compiled part is get deleted by the python(as soon as you execute your code) just it does not want programmers to get into complexity.

Code : Sample Python code





print("i am learning python")
print("i am enjoying it")


now if you run this code using command prompt just save this above code in notepad and save with the extension “.py”
syntax: python (name of the and press enter.
Note: If you are writing code in the notepad just save the code with extension “py” inlet suppose you have created a folder named python_prog in d drive.

as you press enter the byte code will get generated. A folder created and this will contain the byte code of your program. This folder is in the python_prog folder where you will save your python codes.

now to run the compiled byte code just type the following command in the command prompt:-

the extension .pyc is python compiler..

Thus, it is proven that python programs are both compiled as well as interpreted!! but the compilation part is hidden from the programmer.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.