What is it?
A Python “implementation” is defined as a programme or environment that supports the execution of programmes written in the Python language, as represented by the CPython reference implementation.
There have been and continue to be several distinct software packages that provide what we all know as Python, though some of those are more like distributions or variants of some existing implementation than a completely new implementation of the language.
In much simpler words
Python is classified as an interpreted language, but this is only partially correct because a compilation step is required to convert the Python code into bytecode, which is stored in a.pyc or.pyo format and is deleted once the programme is executed. Bytecode is another binary representation that a virtual machine can execute (not by CPU directly). The virtual machine (which differs depending on the machine) converts binary instructions into machine instructions.
A few of the famous Python implementations are –
PyPy: This is a Python implementation that is written in Python (RPython). The reference Python (CPython) converts the code to bytecode and then runs it through an interpreter, which is slower than machine code. PyPy employs JIT (Just-In-Time compilation), which compiles code during execution time, making it much faster. An example of PyPy code is provided below.
class Tape(object):
def init(self):
self.thetape = [0]
self.position = 0
def get(self):
return self.thetape[self.position]
def set(self, val):
self.thetape[self.position] = val
def inc(self):
self.thetape[self.position] += 1
def dec(self):
self.thetape[self.position] -= 1
def advance(self):
self.position += 1
if len(self.thetape) <= self.position:
self.thetape.append(0)
def devance(self):
self.position -= 1
Jython: It is a Python implementation that runs on the Java platform. Also is then compiled into Java bytecode, which can be executed in a Java virtual machine. Python modules are replaced by Java classes. An example of Jython code is given right here.
from org.jython.book.interfaces import BuildingType
class Building(BuildingType):
def init(self, name, address, id):
self.name = name
self.address = address
self.id = id
def getBuildingName(self):
return self.name
def getBuildingAddress(self):
return self.address
def getBuldingId(self):
return self.id
package org.jython.book.interfaces;
public interface BuildingType {
public String getBuildingName();
public String getBuildingAddress();
public String getBuildingId();
}
IronPython: It is written in C# and uses the.Net (Common Language Runtime) virtual machine, similar to Jython. IronPython, unlike CPython, does not have a Global Interpreter Lock (GIL) and is thus better suited for multithreaded applications. An example of IronPython is given below
import sys
sys.path.append(r'C:\Python24\Lib')
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import Application, Form
class HelloWorldForm(Form):
def init(self):
self.Text = 'Hello World'
self.Name = 'Hello World'
form = HelloWorldForm()
Application.Run(form)
So that is it for today guys! Hope you understood the topic well! For more content like this, stay connected with engineers planet! See you soon.
Looking for assistance and guide in accomplishing your projects? Reach out to us on WHATSAPP for instant help.