What is Python?

Python Logo

First, what is 'Programming'?

Being good at programming is not only knowing a lot about a programming language, or how to write very fast programs. It is about:

  • understanding a problem conceptually and being able to translate it into code
  • thinking of new ways to tackle (for example) a scientific problem, and knowing what tools to use
  • knowing how to fix your program when it does not work
  • writing a program that is fast enough, not the fastest possible
  • writing a program that can be understood by other people (or by yourself after some time has passed)

In science, the last point is important, because reproducible research and open science is becoming the norm in certain fields of research. This means that others have to be able to read your code, and understand what you are doing, and be able to run it themselves. For this course, we are not just interested in whether your solutions are correct, but also whether it is possible to understand how you are solving the problem. You should always write code assuming that someone else may read it.

This course focuses on aspects of programming that would be useful to you in scientific research, but Python is a very popular language, and what you will learn will also be applicable if you decide to pursue a different career!

How does Python compare to other languages?

Python is an interpreted language, which means that the code is not compiled in advance. This makes it slower than languages like C/C++ or Fortran. Why would we want to learn/use it then?

  • It has a clean and simple syntax which emphasises readability
  • It can be much faster to write programs in Python than other languages
  • It gives detailed errors by default which makes it easier to fix bugs
  • It is easy to use for interactive analysis
  • It has a large "ecosystem" of packages available for everything from numerical analysis, databases, graphical interfaces, plotting, accessing remote data...
  • It is straightforward to interface with C/Fortran code making parts of the code super fast and efficient
  • It can interact with command-line programs, and other languages
  • Some Packages (e.g. Numpy) are written in C, which means that we get the convenience of Python and the speed of C

Why is it called 'Python'?

Even though the Python logo has snakes in it, Python originally comes from the Monty Python comedy group ["Monty Python's Flying Circus", "Monty Python's Life of Brian", "Monty Python and the Holy Grail"]

... a lot of Python documentation includes jokes related to Monty Python.

A note on Python 2 vs 3

The last stable Python version is 3.7, but quite some people are still using version 2.7 (the latest 2.x release) because Python 3 includes some significant changes such that not all previously written code automatically runs with Python 3. Please note that Python 2 support ended in Jan 2020 and many major Packages will no longer continue their code development for Pyhton 2.7 (Python 3 statement - Sunsetting Python 2 support. Hence, we will teach Python 3 in this course and you should seriously consider to stop using Python 2 if you still do. Converting Python 2 code to 3.x is as easy as running 2to3 your-old-code.py on the command line.

In [ ]: