Python Implementations


This entry is part 4 of 4 in the series Python

What is a Python implementation? First of all, when we talk about Python we are talking about two separate things that are closely related: language and implementation. Language is simply a set of rules for writing code, not unlike vocabulary and grammar. The implementation is a program that understands those rules and can execute code. When we downloaded Python from python.org, we downloaded the default implementation of Python which was CPython. CPython is a program written in C language, that’s why it’s called CPython. CPython is the default. There are others.

Machine Code

Our computers and phones and other machines take instructions in the form of zeros and ones, which is machine code. We write these programs in a human-like language such as Python and then run other programs to translate that into machine language for our specific machine to understand. The zeros and ones for a Windows computer are different than the zeros and ones for a Mac or a Linux machine. A program written for Windows will not run on a Mac and vice versa.

Implementations

Other than CPython, there are Jython (Java), IronPython (C#) and PyPy (Subset of Python). What does this mean? Jython is written in the Java language. If you have some Java code that you have written, you could use that code in your Python program by using Jython instead of CPython. If you are a C# developer and you want to use some C# code in your Python program you will have to use IronPython.

How is Python code executed?

When we write a computer program, we write it in a language like C, C# or Java. The Java compiler does not compile the Java code we write into machine code. It compiles it into a portable language called Java Bytecode. This Bytecode is not specific to Windows or Mac. The Java Virtual Machine (JVM) converts Java Bytecode to Machine code. The JVM operates at run time to convert Bytecode to machine code. We can run Java Bytecode on any platform that has a JVM.

Python Code -> CPython -> Python Bytecode -> Python Virtual Machine -> Machine Code.

Python Code – Jython -> Java Bytecode -> Java Virtual Machine -> Machine Code.

Series Navigation<< Python in Visual Studio Code