Appearance
Python Interpreters
When we write Python code, we obtain a text file containing Python code with a .py
extension. To run the code, a Python interpreter is needed to execute the .py
file.
Since the entire Python language, from specifications to interpreters, is open-source, theoretically, as long as one has sufficient skill, anyone can write a Python interpreter to execute Python code (though it is certainly difficult). In fact, there are multiple Python interpreters available.
CPython
After downloading and installing Python 3.x from the official Python website, we directly obtain an official version of the interpreter: CPython. This interpreter is developed in C, hence the name CPython. Running python
in the command line starts the CPython interpreter.
CPython is the most widely used Python interpreter. All the code in this tutorial is executed under CPython.
IPython
IPython is an interactive interpreter built on top of CPython, meaning that IPython only enhances the interactive interface, but the functionality of executing Python code is exactly the same as CPython.
CPython uses >>>
as the prompt, while IPython uses In [number]:
as the prompt.
PyPy
PyPy is another Python interpreter focused on execution speed. PyPy employs JIT (Just-In-Time) technology to dynamically compile Python code (note: not interpret), thus significantly improving the execution speed of Python code.
Most Python code can run under PyPy, but PyPy and CPython have some differences, which means the same Python code may produce different results when executed under the two interpreters. If you intend to run your code under PyPy, you need to understand the differences between PyPy and CPython.
Jython
Jython is a Python interpreter that runs on the Java platform and can directly compile Python code into Java bytecode for execution.
IronPython
IronPython is similar to Jython, but it runs on the Microsoft .NET platform and can directly compile Python code into .NET bytecode.
Summary
There are many Python interpreters, but CPython is still the most widely used. If you need to interact with Java or the .NET platform, the best approach is not to use Jython or IronPython, but to interact via network calls to ensure the independence of each program.
All the code in this tutorial is guaranteed to run only under CPython 3.x versions. Please make sure to install CPython locally (that is, the installer downloaded from the official Python website).