Introduction to Programming#
Before you can work with data in Python, you need to know some basics of the Python language as well as some basic programming concepts. These concepts will underlie everything you do when you work with data. Thus, they will help you even when you work in Excel, Tableau, or whatever.
What is Programming?#
Computers are dumb. They can only do what they are instructed to do. Thus, we humans use programming languages to tell computers what to do.
A computer program is simply a set of instructions for a computer. When you write a computer program, your code is translated into instructions that the computer can understand. Programs are written in a programming language. There are many programming languages out there and each is a different way of telling a computer what to do. Over the years, programmers have created different languages, each with its advantages and disadvantages, and as a result these languages tend to evolve for different use cases. For example, PHP and JavaScript are frequently used to create websites, while C++ is often used to create games. Python was originally developed as an easy-to-use, general purpose language and has since evolved into the premiere language for data science and data analysis.
A computer program is similar to a cooking recipe. A recipe is a set of steps that, when followed, leads to a desired outcome (yummy food). For example, here’s a simple recipe for making whipped cream (courtesy of this website):
Obtain a metal mixing bowl, a metal whisk, 1 cup of heavy whipping cream, and 2 tablespoons of sugar.
Place a metal mixing bowl and metal whisk into the freezer for 10 minutes.
Remove bowl and whisk from freezer and place on kitchen countertop.
Add 2 tablespoons of sugar to the bowl.
Add 1 cup of heavy whipping cream to the bowl.
Do {
Whisk cream and sugar mixture.
} Until (stiff peaks are visible)
If you can understand the above recipe, you can write a computer program. Steps 1 - 5 are imperative statements: they tell the cook to take a specific action. Step 6 is more interesting. It’s a “loop”. It tells the cook to repeat an action until a condition is met. Once the condition is met, the cook will terminate the action. Such loops are common in programming. You will learn more more about loops in the next section on control flow.