cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
109
Views
0
Helpful
2
Replies

How does Python compile code?

Mitrixsen
Level 1
Level 1

Hello, everyone.

I don't quite understand this part that my book explains about Python
"Python is an interpreted language, which means it executes instructions directly, without the need to compile the program first."

I haven't programmed much before but isn't the compiler what translates the code that we write into machine readable code? So does Python still use a compiler or not? There has to be something that will translate the code, right?

That's all,
David

2 Replies 2

The book has simplifies as in Python the compilation step is largely invisible for most Python users. 

Python is considered "interpreted language" because from the user perspective as a coder, it does act like one. We write our Python code (save this as a .py file) then we can the run it using the Python interpreter, without explicitly compiling it into a standalone executable beforehand. There is a LOT more to this behind the curtain https://eddieantonio.ca/blog/2023/10/25/python-is-a-compiled-language/

So in short, Yes, Python does use a compiler, but it is an internal step that you typically don't interact with directly. It compiles your code into bytecode, not directly into machine code.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Hello David,

2 yes! Yes, python use a compiler _ but it compiles to bytecode, not direct machine code. And yes, Python is interpreted—but by its own runtime that executes the bytecode.

From your everyday coding experiense, it feel like an interpreted language ; no manual compile steps, no standalone executable, just “python myscript.py” and it runs.

 

Best regards
.ı|ı.ı|ı. If This Helps, Please Rate .ı|ı.ı|ı.