1
$\begingroup$

I just read this Why doesn't Python need a compiler?

I know that Python isn't absolutely compiler or interpreted but it is both of them it's maybe an interpretive, high-level, and all-purpose programming language. Python uses PVM(interpreter) and Bytecode(that is output of a compiler). after all, why do we classify Python as a compiler language in comparison to C for example? what does make Python different from C which is quicker than Python?

$\endgroup$
3
1
$\begingroup$

The compilation process is a process of taking code from language "A" and translating it to code from language "B".


Lets start by saying that python doesn't compile at all - it stays python code all of the time.

On the other hand, $C$ compiles into assembly, which then turns into a standalone executable.

Since python stays python, this means that to run python code, you will need a special program - an interpreter. This interpreter reads the python code line-by-line, and executes it. But $C$ compiles into assembly, which is natural for the computer and can be executed without requiring help from other programs.

While creating an interpreter is usually simpler, a compiler is a much better option - here are a few advantages:

  • Compiled code doesn't need to rely on external programs to run code
  • The compiler can catch some errors even before the program is executed, while this is not possible when using an interpreter
  • A compiler is capable of introducing optimizations into the compiled code, so that it will run faster (nowadays, its significantly faster!)

All of that being said, even though python is an interpreted language, it doesn't make it a bad one. The core concept of python is being simple, easy to learn and use, and still powerful - and python achieves those well.


Important note

In this answer I was talking about the most basic versions and usages of python and $C$. Yes, you can create a compiler for any language, even python. And yes, python already isn't a "fully" interpreted language - there are some compilation steps that are done. But it is still considered an interpreted language since there really isn't a native compiler that translates it into machine code (assembly)

$\endgroup$
6
  • $\begingroup$ Python converts the code into some intermediate representation. It's not stored as text. You can even compile python code into "python bytecode". $\endgroup$ Oct 19 at 12:52
  • $\begingroup$ @YuvalFilmus please feel free to edit my answer and correct whatever you deem necessary! I tried in my answer to amplify the differences, so there is a good chance I might have oversimplified some things (and hence they won't be correct) $\endgroup$
    – nir shahar
    Oct 19 at 14:17
  • $\begingroup$ @YuvalFilmus Thank you, sir. but i don't understand what is the reason that python doesn't use just a native compiler by itself? $\endgroup$
    – jasmine
    Oct 19 at 16:57
  • $\begingroup$ @nirshahar Thank you I realize it now. so we know python is easy to read and learn, this could be because it doesn't use a native compiler? i just wonder $\endgroup$
    – jasmine
    Oct 19 at 17:02
  • $\begingroup$ Not really, but it does have a (small) part in it. One thing that this interpreter enables, is dynamic types. This means that a single variable isn't bound to have a particular type all of the time - it could sometimes be an integer and other times a string. Practically, this allows for simpler syntax which helps the language to be easier to learn and master. $\endgroup$
    – nir shahar
    Oct 19 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.