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
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 program.py) 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.
- Important differences between Python 2.x and Python 3.x with examples
- Python | Convert list to Python array
- Reading Python File-Like Objects from C | Python
- Python | Merge Python key values to list
- Python | Index of Non-Zero elements in Python list
- Python | Add Logging to Python Libraries
- Python | Sort Python Dictionaries by Key or Value
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Add Logging to a Python Script
- Python | Visualizing O(n) using Python
- Python | a += b is not always a = a + b
- try-except vs If in Python
- abs() in Python
- try and except in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.