Module1-Elective 4
Module1-Elective 4
1
MODULE TITLE
MODULE OVERVIEW
This module provides a concept relevant to Python Programming Language. It provides the learners
an understanding of different compilers and interpreters' platforms. The instructor is also expected
to demonstrate the different features of the identified IDE and interpreter for the course.
LEARNING OBJECTIVES
LEARNING CONTENTS
Python is a free general-purpose programming language with beautiful syntax. It is available across
many platforms including Windows, Linux, and Mac OS. Due to its
inherently easy to learn nature along with Object-Oriented features,
Python is used to develop and demonstrate applications quickly.
Python has the “batteries included” philosophy wherein the standard
programming language comes with a rich set of built-in libraries. It’s a
known fact that developers spend most of the time reading the code
than writing it and Python can speed up software development. Hosting
solutions for Python applications are also very cheap. Python Software
Foundation (PSF) nurtures the growth of the Python programming
language. A versatile language like Python can be used not only to
write simple scripts for handling file operations but also to develop
massively trafficked websites for corporate IT organizations.
Python was conceived in the late 1980s and its implementation was Guido van Rossum—Creator and
BDFL of Python Programming
started in December 1989 by Guido van Rossum at Centrum Wiskunde Language. (Image courtesy of
& Informatica (CWI) in the Netherlands as a successor to the ABC Wikipedia.org)
programming language, which was inspired by SETL[(SET Language)
is a very high-level programming language based on the mathematical theory of sets], capable of
exception handling and interfacing with the Amoeba operating system.
Van Rossum is Python’s principal author, and his continuing central role in deciding the direction of
Python is reflected in the title given to him by the Python community. He is the “Benevolent Dictator
For Life” (BDFL), which means he continues to oversee Python development and retains the final
say in disputes or arguments arising within the community.
Back in the 1970s, there was a popular BBC comedy TV show called “Monty Python’s Flying Circus”
and Van Rossum happened to be a big fan of that show. At the time when he began implementing
Python, Guido van Rossum was also reading the published scripts from “Monty Python’s Flying
Circus.” It occurred to him that he needed a name that was short, unique, and slightly mysterious,
so he decided to call the language “Python.”
Versions of Python:
• The first-ever version of Python (i.e., Python 1.0) was introduced in 1991. Since its inception
and introduction of Version 1, the evolution of Python has reached up to Version 3. x (till
2018).
• Python 2.0 was released on 16 October 2000 and had many major new features, including
a cycle-detecting garbage collector and support for Unicode. With this release, the
development process became more transparent and community-backed.
• Python 2.7's end-of-life date was initially set at 2015 then postponed to 2020 out of concern
that a large body of existing code could not easily be forward-ported to Python 3. No more
security patches or other improvements will be released for it. With Python 2's end-of-life,
only Python 3.6.x and later are supported.
• Python 3.0 (initially called Python 3000 or py3k) was released on 3 December 2008 after a
long testing period. It is a major revision of the language that is not completely backward-
compatible with previous versions. Many of its major features were backported to Python
2.6.x and 2.7.x version series. Releases of Python 3 include the 2to3 utility, which automates
(at least partially) the translation of Python 2 code to Python 3.
• Python 3.9.2 and 3.8.8 were expedited as all versions of Python (including 2.7) had security
issues, leading to possible remote code execution and web cache poisoning.
There are a large number of high-level programming languages available, such as C, C++, and
Java. The good news is all high-level programming languages are very similar to one another. What
differs is mainly the syntax, the libraries available, and the way we access those libraries. A library
is simply a collection of resources and pre-written codes that we can use when we write our
programs. If you learn one language well, you can easily learn a new language in a fraction of the
time it took you to learn the first language.
Because there are many programming languages available today, the usual question to be an ask
by a newbie to the programming environment is “Why Do People Use Python?”. Given that there
are roughly more than a million Python users out there at the moment, there is no way to answer
this question with complete accuracy; the choice of development tools is sometimes based on
unique constraints or personal preference.
• High level
1. High-level languages are platform-independent which means that the programs written
in a high-level language can be executed on different types of machines.
2. A program written in the high-level language is called a source program or source code
and is any collection of human-readable computer instructions.
3. However, for a computer to understand and execute a source program written in a high-
level language, it must be translated into machine language. This translation is done
using either a compiler or interpreter.
4. A compiler is a system software program that transforms high-level source code written
by a software developer in a high-level programming language into a low-level machine
language.
5. The process of converting high-level programming language into machine language is
known as compilation.
6. Compilers translate source code all at once and the computer then executes the
machine language that the compiler produced.
7. Not all source code is compiled. With some programming languages like Python, the
source code is frequently executed directly using an interpreter rather than first compiling
it and then executing the resulting machine language.
8. An interpreter is a program that reads source code one statement at a time, translates
the statement into machine language, executes the machine language statement, then
continues with the next statement.
9. A programming paradigm is a style or “way” of programming. Major programming
paradigms are:
• An imperative is a paradigm of computer programming in which the program
describes a sequence of steps that change the state of the computer as each
one is executed in turn. Imperative programming explicitly tells the computer
“How” to accomplish a certain goal.
• Logical. The logical paradigm fits exceptionally well when applied to problem
domains that deal with the extraction of knowledge from basic facts and rules.
Rules are written as logical clauses with a head and a body; for instance, "Y is
true if X1, X2, and X3 are true." The idea in logical programming is that instead
of telling the computer how to calculate things, you tell it what things are.
Example: PROLOG.
• Functional. In functional programming languages, functions are treated as first-
class objects. In other words, you can pass a function as an argument to another
function, or a function may return another function.
• Object-Oriented. Object-oriented is the term used to describe a programming
approach based on objects and classes. The object-oriented paradigm allows us
to organize software as a collection of objects that consist of both data and
behavior.
• Scalable
1. The term "scalable" is most often applied to measuring hardware throughput and usually
refers to additional performance when new hardware is added to a system.
2. Python provides basic building blocks on which you can build an application, and as
those needs expand and grow.
3. Python's pluggable and modular architecture allows your project to flourish as well as
maintain manageability.
• Portable
1. Python can be found on a wide variety of systems, contributing to its continued rapid
growth in today's computing domain.
2. Python is available on practically every type of platform that has an ANSI C compiler.
Although there are some platform-specific modules, any general Python application
written on one system will run with little or no modification on another.
3. Portability applies across multiple architectures as well as operating systems.
• Easy-to-learn − Python has few keywords, a simple structure, and a clearly defined syntax.
This allows the student to pick up the language quickly.
• Easy-to-read − Python code is more clearly defined and visible to the eyes.
• A broad standard library − Python's bulk of the library is very portable and cross-platform
compatible on UNIX, Windows, and Macintosh.
• Interactive Mode − Python has support for an interactive mode that allows interactive
testing and debugging of snippets of code.
• GUI Programming − Python supports GUI applications that can be created and ported to
many system calls, libraries, and windows systems, such as Windows MFC, Macintosh, and
the X Window system of Unix.
Every Python implementation comes with several built-in and standard modules. These are
documented in The Python Standard Library. A few built-in modules are mentioned when they
interact in a significant way with the language definition. The implementation of Python is divided
into three categories:
Reference implementation
CPython is the reference implementation of Python. It is written in C, meeting the C89 standard with
several select C99 features (with later C versions out, it's considered outdated; CPython includes
its C extensions, but third-party extensions are not limited to older C versions, can e.g. be
implemented with C11 or C++). It compiles Python programs into an intermediate bytecode which
is then executed by its virtual machine. CPython is distributed with a large standard library written
in a mixture of C and native Python. It is available for many platforms, including Windows (starting
with Python 3.9, the Python installer deliberately fails to install on Windows 7 and 8; Windows
XP was supported until Python 3.5) and most modern Unix-like systems, including macOS
(and Apple M1 Macs, since Python 3.9.1, with experimental installer) and unofficial support
•PyPy is a fast, compliant interpreter of Python 2.7 and 3.6. Its just-in-time
compiler brings a significant speed improvement over CPython but several libraries
written in C cannot be used with it.
• Stackless Python is a significant fork of CPython that implements microthreads; it does
not use the call stack in the same way, thus allowing massively concurrent programs.
PyPy also has a stackless version.
• MicroPython and CircuitPython are Python 3 variants optimized for microcontrollers,
including Lego Mindstorms EV3.
• Pyston is a variant of the Python runtime that uses just-in-time compilation to speed up
the execution of Python programs.
• Cinder is a performance-oriented fork of CPython 3.8 that contains several optimizations
including bytecode inline caching, eager evaluation of coroutines, a method-at-a-
time JIT, and an experimental bytecode compiler.
Unsupported implementations
Other just-in-time Python compilers have been developed, but are now unsupported:
•Google began a project named Unladen Swallow in 2009, intending to speed up the
Python interpreter fivefold by using the LLVM, and improving its multithreading ability to
scale to thousands of cores, while ordinary implementations suffer from the global
interpreter lock.
• Psyco is a discontinued just-in-time specializing compiler that integrates with CPython
and transforms bytecode to machine code at runtime. The emitted code is specialized
for certain data types and is faster than the standard Python code. Psyco does not
support Python 2.7 or later.
• PyS60 was a Python 2 interpreter for Series 60 mobile phones released by Nokia in
2005. It implemented many of the modules from the standard library and some additional
modules for integrating with the Symbian operating system. The Nokia N900 also
supports Python with GTK widget libraries, enabling programs to be written and run on
the target device.
Cross-compilers to other languages
There are several compilers to high-level object languages, with either unrestricted Python, a
restricted subset of Python, or a language similar to Python as the source language:
• Cython compiles (a superset of) Python 2.7 to C (while the resulting code is also usable
with Python 3 and also e.g. C++).
• Nuitka compiles Python into C++.
• Pythran compiles a subset of Python 3 to C++.
• Pyrex (latest release in 2010) and Shed Skin (latest release in 2013) compile to C and
C++ respectively.
• Google's Grumpy (latest release in 2017) transpiles Python 2 to Go.
• IronPython (now abandoned by Microsoft) allows running Python 2.7 programs on the
.NET Common Language Runtime.
• Jython compiles Python 2.7 to Java bytecode, allowing the use of the Java libraries from
a Python program.
• MyHDL is a Python-based hardware description language (HDL), that converts MyHDL
code to Verilog or VHDL code.
Note:
In summary, this is the list of Implementation for python:
Implementations of Python include:
• CPython – The reference implementation, written in C89. Some notable distributions include:
o PSF Python – Reference distribution that includes only selected standard libraries
o ActivePython – Distribution with more than 300 included packages
o Intel Distribution for Python – High-performance distribution with conda and pip package
managers.
• Stackless Python – CPython with coroutines
• MicroPython – Python 3 implementation for microcontroller platforms
• CLPython – Implementation, written in Common Lisp
• Cython – programming language to simplify writing C and C++ extension modules for the
CPython Python runtime.
• IronPython – Python for CLI platforms (including .NET and Mono)
• Jython – Python for Java platforms
• Pyjs – a framework (based on Google Web Toolkit (GWT) concept) for developing client-side
Python-based web applications, including a stand-alone Python-to-JavaScript compiler,
an Ajax framework, and widget toolkit
• PyPy – Python (originally) coded in Python, used with RPython, a restricted subset of Python that
is amenable to static analysis and thus a JIT.
• Numba – NumPy aware LLVM-based JIT compiler
• Shed Skin – a source-to-source compiler from Python to C++
• Nuitka – a source-to-source compiler that compiles Python code to C/C++ executables, or source
code.
A. The instructor may demonstrate the features of either of the two suggested IDEs:
- Visual Studio
- Pycharm
- List of Other IDE related to Python Programming Source: Wikipedia
• Database tools
Access Oracle, SQL Server, PostgreSQL, MySQL, and other databases right
from the IDE. Rely on PyCharm’s help when editing SQL code, running queries,
browsing data, and altering schemas.
Web Development
In addition to Python, PyCharm provides first-class support for various Python web
development frameworks, specific template languages, JavaScript, CoffeeScript,
TypeScript, HTML/CSS, AngularJS, Node.js, and more.
• Python Web frameworks
PyCharm offers great framework-specific support for modern web development
frameworks such as Django, Flask, Google App Engine, Pyramid, and web2py,
including Django templates debugger, manage.py, and appcfg.py tools, special
autocompletion and navigation, just to name a few.
• Live Edit
Live Editing Preview lets you open a page in the editor and the browser and see
the changes being made in code instantly in the browser. PyCharm auto-saves
your changes, and the browser smartly updates the page on the fly, showing your
edits.
Scientific Tools
PyCharm integrates with IPython Notebook, has an interactive Python console, and
supports Anaconda as well as multiple scientific packages including Matplotlib and
NumPy.
• Interactive Python console
You can run a REPL Python console in PyCharm which offers many advantages
over the standard one: on-the-fly syntax check with inspections, braces, and
quotes matching, and of course code completion.
• Conda Integration
Keep your dependencies isolated by having separate Conda environments per
project, PyCharm makes it easy for you to create and select the right
environment.
• Plugins
More than 10 years of IntelliJ platform development gives PyCharm 50+ IDE
plugins of different nature, including support for additional VCS, integrations with
different tools and frameworks, and editor enhancements such as Vim emulation.
• Cross-platform IDE
PyCharm works on Windows, macOS, or Linux. You can install and run PyCharm
on as many machines as you have, and use the same environment and
functionality across all your machines.
Step 1) install the Python extension for VS Code from the Visual Studio Marketplace. For additional
details on installing extensions, see Extension Marketplace. The Python extension is
named Python and it's published by Microsoft.
Step 2) Select your Python interpreter by clicking the status bar. A dialog box will appear. Choose
your appropriate interpreter.
Status Bar
Dialog box
You can download applications for creating and navigating programs on python. Go to Google
Play Store or Apps Store and Download app/s suitable to you. You can choose:
LEARNING POINTS
Python is a free general-purpose programming language with beautiful syntax. It is available across
many platforms including Windows, Linux, and Mac OS.
Python was conceived in the late 1980s and its implementation was started in December 1989 by
Guido van Rossum.
Why Python? Because of its best features such as high-level programming, scalable, easy to, read,
easy to learn, portable, and so on.
IDEs mentioned in this module are Pycharm and Visual Studio Code
Prepared by:
PATRICK V. MOLE, MIT
Faculty, College Information
and Technology Education