Is Python Interpreted or Compiled? | Is Python a Compiled language? -Code Star

Before Diving into the deep meaning and answers of this question we first need to know , that what are compilers & what are interpreters.



Compilers-  Computer software that translates (compiles) source code written in a high-level language (e.g., C++) into a set of machine-language(binary code)  instructions that can be understood by a digital computer's CPU. Compilers are very large programs, with error-checking and other abilities. Compiler scans the entire program and translates the whole of it into machine code at once. It shows error after running the whole programme.


Interpreters-Interpreters also translate source code written in high-level language into binary code.A Interpreter scans the program line by line and shows error at every errored line.




So, now we know that what are interpreters and compilers.

Now, talking about Python, it is both interpreted and as well as compiled language.


So, How does this happen?



A Python code is written in a .py file. When this code is executed it is first compiled into bytecode which is stored in .pyc format.

This bytecode is a low-level set of instructions that can be executed by an interpreter. While in Python the interpreter is called as CPython which is written in C language which then translates this bytecode into machine code & then executes the code in the Virtual Machine.

This is how Python works & executes a code using both compilers and interpreter.



One popular advantage of interpreted languages is that they are platform-independent. As long as the Python bytecode and the Virtual Machine have the same version, Python bytecode can be executed on any platform (Windows, MacOS, etc).

Dynamic typing is another advantage. In static-typed languages like C++, you have to declare the variable type and any discrepancy like adding a string and an integer is checked during compile time. In strongly typed languages like Python, it is the job of the interpreter to check the validity of the variable types and operations performed.

Dynamic typing provides a lot of freedom, but simultaneously it makes your code risky and sometimes difficult to debug.

Python is often accused of being ‘slow’. Now while the term is relative and argued a lot, the reason for being slow is because the interpreter has to do extra work to have the bytecode instruction translated into a form that can be executed on the machine. 

If you can talk in your native language to someone, that would generally work faster than having an interpreter having to translate your language into some other language for the listener to understand.



Article By:

Shubham Sagar

Code Star, India

Youtubehttps://www.youtube.com/c/coveringtheworld

E-mailsk0374391@gmail.com















2 comments:

Powered by Blogger.