2. Programming in Python#
Amanda R. Kube Jotte
There are a vast array of problems that can be studied using data science. In order to work on these problems, we need to be able to manipulate and analyze our data using code. One of the most popular programming languages for this purpose is Python, and it will be the primary tool we use throughout this book. In this chapter, we will begin with the basics of programming in Python.
Note
In this book, unless otherwise specified, we are using Python 3.13. We suggest that you ensure the same version of Python is installed on your computer. You can install python from Python.org and Jupyter, a browser-based interace to python, from Jupyter.org. You can also install Python and Jupyter together from Anaconda.com, and the anaconda installation has many data science tools already installed.
You will see short snippets of Python code interwoven with explanatory text. We encourage you to try running these examples on your own computer as you read along.
Python is an interpreted language, which means it executes code line-by-line, starting from the top of a program and moving downward. This will become clearer as you begin writing longer programs, but for now we will focus on small, self-contained examples and build up gradually.
In the next section, you will see how Python can perform simple arithmetic —- much like a calculator. From there, we will expand step by step to more complex operations, illustrating why Python is such a powerful and versatile tool for data scientists.