Is Python a compiled or interpreted language?
sobes.tech AI
Answer from AI
Python is an interpreted programming language. The source code is executed line by line by the interpreter. However, before execution, it is compiled into bytecode and stored in files with the extension .pyc or .pyo. This bytecode is then executed by the Python virtual machine (PVM).
Thus, Python has features of both types: compilation into intermediate bytecode and interpretation of this bytecode. It is often classified as an interpreted language due to its mode of execution.
Example of compilation into bytecode:
# hello_world.py
print("Hello, world!")
After running this script, if it has not been run before, Python will create a file __pycache__/hello_world.cpython-XYZ.pyc (where XYZ depends on the Python version), containing the compiled bytecode. The next time this script is run, it will use the already compiled bytecode to speed up the startup process.