Why Python?#
When it comes to programming languages there are hundreds of options, so perhaps you are wondering why we have selected to use Python in this book. Well, there are several reasons why we feel Python is among the best programming languages to learn.
Python is widely used. This might not seem like a good reason alone for teaching a programming language, but Python’s popularity is a huge asset. Why? Because of Python’s popularity you can find all kinds of excellent resources online related to Python programming practices, common errors, example codes, and more. In many cases, you can simply copy an error message from a Python program into your favorite search engine and you’ll find dozens of posts and replies from users who faced the same error. In many cases you’ll also find solutions to help you resolve the error!
Python is free. There are a few old phrases often used in relationship to software: “free as in beer” and “free as in speech”. Something that is “free as in beer” does not cost money to use, and something that is “free as in speech” is unrestricted in its use. Python is both, and this is another key attribute of the language. Python is an open source programming language with a community of users who have created huge numbers of extensions to the language referred to as libraries. These allow users to access the full potential of the Python language at no cost. This is in contrast to some other languages used widely in the natural sciences, such as MATLAB, which may be free for student use, but rely upon commercial licensing for non-academic usage.
Python is approachable. What does that even mean…? Well, what we mean here is that the threshold to get started using Python is quite low. Python is a type of programming language known as an interpreted language, which means that commands are provided to an intpreter that reads and executes the code on the fly. What this means to us is that we can type in a command to a Python interpreter such as
1 + 1
and when we press the Enter key, the command will be executed by the intpreter and we see the output2
. This is in contrast to compiled programming languages, where the program is converted into code that can be executed by the computer by a compiler. This intermediate step is often a place new programmers get stuck and frustrated. In addition, Python provides clear and detailed error messages that help users to debug their programs efficiently. This is another component that helps make Python approachable, since some other programming languages my simply provide a message indicating an error with little to no indication of what happened (or where in the code).Python is connected. As you may recall from the previous section about computers and programs, Python is one of the programming languages that is often available as an extension to many pieces of scientific software. Geographic Information Systems (GIS) software such as QGIS or ArcGIS now include a Python interpreter built in to the software, where you’re able to use Python to interact with your GIS objects. This kind of connection to other software allows you to extend the ways the software packages work, and customize solutions for your specific data analyis needs.
An of course we could continue this list beyond this point, but perhaps you already have a good sense of why we have chosen Python. Our view is that leaning to program in Python will give you the greatest likelihood of being able to interact with the data of your choice with the lowest threshold for moving from completely new programmer to beginner data scientist!