Atlantic.Net Blog

What is Python: An Intro to a Cross-Platform Programming Language

Python Illustration by Walker Cahall

Target audience

This article assumes the reader has at least a basic familiarity with programming languages.

Introduction

Any Introduction to Computer Science course would be incomplete without a mention of Python. It may seem relatively new to the programming languages scene, but it has been in use since the early 1990s. Scores of large corporations, including Google, Facebook, and even NASA and the Jet Propulsion Laboratory in Pasadena, are among the organizations who make use of Python.
.

Python’s Origin Story

Python was developed by Guido van Rossum in the late 1980s, incorporating what he saw as improvements to the ABC programming language. Because he is a huge fan of Monty Python, the British comedy troupe, he named the language “Python”, even going so far as to call the integrated development environment, or IDE, IDLE in honor of Eric Idle, one of the group’s members.

Van Rossum is still one of the language’s principal authors and contributors, and has received the title of BDFL (Benevolent Dictator For Life) from the Python community.

The Hallmarks of Python

Python is a cross-platform language: a Python program written on a Macintosh computer will run on a Linux system and vice versa. Python programs can run on a Windows computer, as long as the Windows machine has the Python interpreter installed (most other operating systems come with Python pre-installed). An application called py2exe exists that allows a user to create a Windows binary from a Python program so that a Python program developed on another system can be run on a Windows machine that does not have Python installed.

Python differs from many other languages in its use of white space and indentations. While many other languages end programming statements using line endings such as semicolons, Python has no such ending. It also does not enclose code blocks such as for loops and if statements in curly braces. Rather, Python uses indentations to define a code block. Each successive indentation defines a successive block. For example, examine the following code:

if i == 1:
    print "i = 1"
    for x in range(10):
        print "x = ", x
else:
    print "i does not equal 1"

Python interprets the fourth line (print "x= ", x) to be part of the for loop–rather than part of the if statement–because of its level of indentation. Indentation also delineates function and class definitions.

Programming or Scripting Language?

Among aficionados and detractors alike, the question often comes up: is Python a scripting language or a programming language? Before we can try to answer that, let’s review what we mean by differentiating the two.

Programming Languages

Programming languages are compiled by a special program called a compiler. Common languages like C and C++ must be translated by a compiler into machine code–unintelligible to humans–that a computer can read and process. When you write a program in C and compile it, the resulting .o file is what the computer reads. Compiled code usually results in faster code, and the compilation only needs to happen once (unless you change your code). Some compilers do some basic optimization automatically, and others have several flags that can be used to optimize the code for multiple processors and even for parallel processing.

The compiled code a programming language produces most often runs on top of the hardware upon which it’s written. A program written and compiled in C++ is executed directly by the processor on which it was compiled. While this can make the code run faster, it also has the sometimes undesirable effect of making a compiled program processor- and machine-dependent. Code compiled on a particular computer may not even run on a separate, nearly identical machine, due to small differences in hardware.
.

Scripting Languages

Scripting languages, on the other hand, are read and interpreted each time you run them, without a compiler creating a machine-language file. No optimization takes place, so if you write sloppy code, then you’ll get sloppy results, which can result in slower programs.

Scripting languages also run “inside” another program, rather than running directly on their host processor. PHP runs inside the PHP scripting engine, for example, and bash scripts run inside the bash shell. (An exception to this rule is Java; Java is considered a programming language, but it runs inside the Java Virtual Machine (JVM)).
.

The Verdict

So what is Python? While often called a programming language, Python is, technically, a scripting language. Its code uses no compiler and can run on just about any device that runs the Python shell. It also shares a couple of other similarities to scripting languages over programming languages.

Scripting languages are often less rigid when it comes to syntax and format. White space is treated more forgivingly (with the exception of indentation, mentioned earlier). As a result, programmers need not spend hours debugging code trying to find a misplaced semicolon or a missing curly brace. It is a matter of pride for many Python programmers that their code is easily readable by a human, making it easier to debug, when necessary.

Programming languages (such as C++) tend to be more syntactically complex and difficult to learn, while scripting languages are less intimidating. Consider a “Hello, world” program in C++:

#include <iostream>;  
using namespace std;  
int main(){  
      cout << "Hello, world!" << endl;  
      return 0;  
}

.
Now, the same program in Python:

print "Hello, world!"

.
Because it is not a compiled language, some programming purists disparage Python, saying that it can be slow and less efficient. As processors improve in speed and architecture, though, there becomes less appreciable speed difference between a compiled language and a scripted one. Only where serious performance is an issue might a difference between the two become apparent.
.

The Python Version Schism

Newcomers to the Python environment may notice and wonder about the differences between version 2 and version 3 of the language. Unlike most software releases, the two versions exist simultaneously and separately and are not completely compatible with each other.

Version 3.0 was released in December of 2008 and was designed to fix certain flaws in the language–mainly by removing some duplicate ways of performing some tasks. It is not fully backwards-compatible with version 2, though, and programs written in 2.7 may break when ported to version 3. For a short time, its development paralleled version 2, but that parallel development ceased with version 3.2 in February 2011. Tools do exist to make portability and conversion a little easier.

When a programmer begins to work in Python, he or she must decide which version to use. As of this writing, the most commonly used version is 2.7. It is also the final 2.x version; all future releases will be for version 3.x. So, even though version 2.7 is officially end-of-life, it is still a popular choice for its extensive collection of libraries. Until version 3.x’s adoption and use rate increases (and the community develops this version’s library support), this schism may continue to persist.
.

Conclusion

Python is an extremely capable language that many software developers find it worthwhile to learn. Its portability and ease of use, as well as its accessibility to new programmers, make it an extremely attractive solution to many programming problems and applications.

For more interesting articles and how-to’s – like How to: Python 3 and Creating a Virtual Environment(venv) in CentOS 6.7 – be sure to head on over to our blog.

Atlantic.Net

Altantic.Net offers many VPS hosting, managed cloud hosting, one-click application cloud installations and many other hosting solutions.
.
.

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year