Python is a general-purpose programming language in a similar vein to other programming languages that you might have heard of such as C++, JavaScript or Microsoft's C# and Oracle's Java.

It has been around for some considerable time having been originally conceived back in the 1980s by Guido van Rossum at Centrum Wiskunde & Informatica (CWI) in the Netherlands. The language is named after one of Guido's favorite programs "Monty Pythons Flying Circus", a classic and somewhat anarchic British comedy sketch show originally running from 1969 to 1974 (but which has been re-run on various stations ever since) and with several film spin offs. You will even find various references to this show in the documentation available with Python.

As a language it has gained interest over recent years, particularly within the commercial world, with many people wanting to learn the language. This increased interest in Python is driven by several different factors:
  • Its flexibility and simplicity which makes it easy to learn.
  • Its use by the Data Science community where it provides a more standard programming language than some rivals such as R.
  • Its suitability as a scripting language for those working in the DevOps field where it provides a higher level of abstraction than alternative languages traditionally used.
  • Its ability to run on (almost) any operating system, but particularly the big three operating systems; Windows, MacOS and Linux.
  • The availability of a wide range of libraries (modules) that can be used to extend the basic features of the language.
  • And the most important one, it is free of cost.

Python itself is now managed by the not-for-profit Python Software Foundation which was launched in March 2001. The mission of the foundation is to foster development of the Python community; it is also responsible for various processes within the Python community, including developing the core Python distribution, managing intellectual rights and supporting developer conferences including PyCon.

Python Versions

Currently there are two main versions of Python called Python 2 and Python 3.
  • Python 2 was launched in October 2000 and has been, and still is, very widely used.
  • Python 3 was launched in December 2008 and is a major revision to the language that is not backward compatible.
  • The issue between the two versions can be highlighted by the simple print facility:
  • In Python 2 this is written as print 'Hello World'
  • In Python 3 this is written as print ('Hello World')

It may not look like much of a difference but the inclusion of the ' () ' marks a major change and means that any code written for one version of Python will probably not run on the other version. There are tools available, such as the 2-3 utility, that will (partially) automate translation from Python 2 to Python 3 but in general you are still left with significant work to do.

This then raises the question which version to use? Although interest in Python 3 is steadily increasing there are many organizations that are still using Python 2. Choosing which version to use is a constant concern for many companies.

However, the Python 2 end of life plan was initially announced back in 2015 and although it has been postponed to 2020 out of concern that a large body of existing code could not easily be forward-ported to Python 3, it is still living on borrowed time. Python 3 is the future of the Python language and it is this version that has introduced many of the new and improved language and library features (that have admittedly been back ported to Python 2 in many cases). We will solely focus on Python 3.

Python Programming

There are several different programming paradigms that a programming language may allow developers to code in, these are:
  • Procedural Programming in which a program is represented as a sequence of instructions that tell the computer what it should do explicitly. Procedures and/or functions are used to provide structure to the program; with control structures such as if statements and loop constructors to manage which steps are executed and how many times. Languages typifying this approach include C and Pascal.
  • Declarative Programming languages, such as Prolog, that allow developers to describe how a problem should be solved, with the language/environment determining how the solution should be implemented. SQL (a database query language) is one of the most common declarative languages that you are likely to encounter.
  • Object Oriented Programming approaches that represent a system in terms of the objects that form that system. Each object can hold its own data (also known as state) as well as define behavior that defines what the object can do. A computer program is formed from a set of these objects co-operating together. Languages such as Java and C# typify the object oriented approach.
  • Functional Programming languages decompose a problem into a set of functions. Each function is independent of any external state, operating only on the inputs they received to generate their outputs. The programming language Haskell is an example of a functional programming language.

Some programming languages are considered to be hybrid languages; that is they allow developers to utilize a combination of difference approaches within the same program. Python is an example of a hybrid programming languages as it allows you to write very procedural code, to use objects in an object oriented manner and to write functional programs. Each of these approaches will be covered in further articles.

Python Libraries

As well as the core language, there are very many libraries available for Python. These libraries extend the functionality of the language and make it much easier to develop applications. These libraries covers:
  • web frameworks such as Django/Flask,
  • email clients such as smtplib (a SMTP email client) and imaplib (an IMAP4 email client),
  • content management operations such as the Zope library,
  • lightweight concurrency (running multiple operations at the same time) using the Stackless library,
  • the Generation of Microsoft Excel files using the Python Excel library,
  • graphics libraries such as Matplotlib and PyOpenGL,
  • machine learning using libraries such as SKLearn and TensorFlow.

Python Execution Model

Python is not a precompiled language in the way that some other languages you may have come across are (such as C++). Instead it is what is known as an interpreted language (although even this is not quite accurate). An interpreted language is one that does not require a separate compilation phase to convert the human readable format into something that can be executed by a computer. Instead the plain text version is fed into another program (generally referred to as the interpreter) which then executes the program for you.

Python actually uses an intermediate model in that, it actually converts the plain text English style Python program into an intermediate 'pseudo' machine code format and it is this intermediate format that is executed. 

The way in which the Python interpreter processes a Python program is broken down into several steps. The steps shown here are illustrative (and simplified) but the general idea is correct.
  1. First the program is checked to make sure that it is valid Python. That is a check is made that the program follows all the rules of the language and that each of the commands and operations etc. is understood by the Python environment.
  2. It then translates the plain text, English like commands, into a more concise intermediate format that is easier to execute on a computer. Python can store this intermediate version in a file which is named after the original file but with a '.pyc' extension instead of a '.py' extension (the 'c' in the extension indicates it contains the compiled version of the code).
  3. The compiled intermediate version is then executed by the interpreter.

When this program is re-run, the Python interpreter checks to see if a '.pyc' file is present. If no changes have been made to the source file since the '.pyc' was created, then the interpreter can skip steps 1 and 2 and immediately run the '.pyc' version of the program.

One interesting aspect of Python's usage is that it can be (and often is) used in an interactive fashion (via the REPL), with individual commands being entered and executed one at a time, with context information being built up. This can be useful debugging situations.

Running the Python Programs

There are several ways in which you can run a Python program, including
  • Interactively using the Python interpreter
  • Stored in a file and run using the Python command
  • Run as a script file specifying the Python interpreter to use within the script file
  • From within a Python IDE (Integrated Development Environment) such as PyCharm, Visual Studio Code, etc.