All Courses

Is Python an Interpreted Language?

Aditya Raj

3 years ago

Is Python an Interpreted Language? | insideAIML
          To answer whether python  is an  interpreted  language  or  not, You  first need  to  know what an interpreter means. In this article, we will try to address this question by looking into different concepts. We will discuss what is an interpreted language, what is a compiler, how an interpreter works, and why is python an interpreted language? Let’s examine each of these questions one by one.
Table of Contents
What is a compiler?
  • Preprocessing
  • Compilation
  • Assembling
  • Linking
What is an interpreter?
What is an interpreted language?
Why is Python an interpreted language?

What is a compiler?

          A compiler is a program that converts a code written in a high-level programming language like C, C++, or Java into machine language. Translating the code written in a high-level programming language to machine language or any other language is called compilation.
The entire process of converting a source code to machine language involves different smaller steps, which are preprocessing, compiling, assembly, and linking. We will discuss each step one by one.


          Preprocessing is the  first step during  compilation.  Preprocessing is  done by  software  named preprocessor.  A preprocessor takes a source code written by the user and processes it. It removes the comments in the source code, expands the macros used in the source code, and includes all the files mentioned in the header of the source code. For example, In C, when we include a header file using the #include<filename> statement, the preprocessor consists of the file in the source code. Similarly, when defining constants and expressions using the  #define statements or macros, the preprocessor expands the symbolic constants at each occurrence. It replaces them using the value or expression defined in the #define statement.
After this entire process, the modified source code is sent to the compiler.


          Once preprocessing is done, the compiler receives the modified source code and converts it to assembly language. This process is called compilation.
Assembly language is an intermediate language between machine code and high-level language and can be understood by humans. It is highly optimized, and all the instructions, including memory locations and registers which are to be used in the program, are specified in this step. 


          After compilation, the program is converted into assembly language code. It is then processed by an assembler and is converted into machine-readable binary code. The process of converting an assembly language code into machine language is called assembling.


          It is the last and final step in the process of compilation. A linker performs linking. The linker collects all the machine codes from different modules to be executed and merges them into a single object file. 
Linking is done to merge all the machine code defined in different libraries so that the program written by the user runs successfully. 
Now, we have understood the working of a compiler. But this information is not sufficient to decide whether a python program is processed using compilation or is interpreted. To be more precise, we will now understand the working of an interpreter.

What is an interpreter?

          An interpreter is a software program used to directly execute a written program in a high-level language such as Python, PHP, Ruby, and JavaScript.
An interpreter converts the code written in a high-level language into an efficient intermediate code called bytecode. The bytecode is then executed line by line on a virtual machine to produce the output.

What is an interpreted language?

          As we know what an interpreter is, we can define what an interpreted language is. An interpreted language is a programming language that an interpreter executes to produce outputs.
Interpreted languages are platform-independent; this is due to the fact that they are run in a virtual machine and need not be specific about the hardware of the machine in which they are being executed.

Why is Python an interpreted language?

          Having discussed compilers, interpreters, and interpreted languages, we are now in a situation to discuss whether python uses compilation or its code is executed by an interpreter. To discuss the question of why Python is an interpreted language, we will first look at how codes written in python are executed on a computer.
Usually, we consider python to be an interpreted language. Is it so, actually? Let’s see.
When we try to execute a python program, the interpreter processed the source code and is converted into bytecode. Bytecodes are low-level codes understandable by the virtual machine. The bytecode is then executed line by line by the virtual machine.
As we know that converting a source code from one language to another is termed compilation, We can say that a python program is also compiled. But to create a bytecode and not a machine code. We can also say that the python program is first compiled to create the bytecode, and then the bytecode is executed line by line by the virtual machine.
Having read all these, Do we have an answer to our question? Is python an interpreted language? YES. Because Python programs are executed line by line by the virtual machine. Is python a compiled language? YES. Because Python programs are compiled from source code to bytecode. How do we explain this?
A programming language being compiled or interpreted is not the property of the language itself. It depends on the implementation of the execution cycle of the programs written in that particular language. Most languages are either fully compiled or fully interpreted, but Python can be exclusively defined as a compiled language or an interpreted language. This is because, during the execution of a python program, it is first compiled to create the bytecode. Then the virtual machine interprets bytecode to produce the outputs.


          This article discussed how programs written in high-level programming languages are executed on a machine. We looked into the concepts of compilers and interpreters. We have also discussed whether we should consider Python as an interpreted language or a compiled language.
We hope you enjoyed the article. If you have any related queries, feel free to ask in the comment section below.
Like the Blog, then Share it with your friends and colleagues to make this AI community stronger. 
To learn more about nuances of Artificial Intelligence, Python Programming, Deep Learning, Data Science and Machine Learning, visit our blog page
Keep Learning. Keep Growing.

Submit Review