Learn to code by doing.

Programming is a way to turn ideas into useful tools, tiny experiments, and things you can share. You do not need experience—just curiosity and a willingness to try.

In this course, we use Python: a friendly, powerful language used for automation, data, web apps, and much more.

Chapter 1

Python Basics

Start with values, variables, collections, and input.

Hello, Python

Code runs one instruction at a time. In this first lesson, the only thing we need to care about is how to send a message back to the screen.

print() is the simplest way to do that. It takes a value, turns it into something the computer can display, and then shows it on its own line. That makes it a useful starting point whenever you want to test an idea quickly.

print("A message for the person using the program")

Run this once before changing anything. Then replace the words between the quotation marks and notice that the structure of the program stays the same while the output changes.

EXAMPLE
Output will appear here.

Write a print() statement that introduces you by name.

EXERCISE
Output will appear here.

Pause after running the example and explain each line in your own words. Notice what the program reads, what it stores, and what it prints, then make one small change and run it again to see exactly what changed.

Practice

Work through the same idea a few times so it starts to feel familiar. Begin by copying the example, then make the single change the instruction asks for, and finally explain to yourself why the result changed.

Type `print("Hello")` and run it.
EXERCISE
Output will appear here.
Replace `Hello` with your own first name.
EXERCISE
Output will appear here.
Add `# I expect: ...` above the print line, then check it.
EXERCISE
Output will appear here.
Print your name on one line and your favorite food on the next.
EXERCISE
Output will appear here.

Values and types

Programs work with different kinds of information: text, whole numbers, decimals, and true-or-false values. The important part here is not just that these kinds exist, but that Python treats them differently.

When you see a value in code, it helps to ask two questions: what is the value, and what type of value is it? That habit becomes useful later when a piece of code behaves differently from what you expected.

"text"     # a string
42         # an integer
True       # a boolean

type() tells us what kind of value Python sees. This is one of the simplest debugging tools you can use when a result looks strange, because it shows whether Python is handling text, numbers, or a boolean.

EXAMPLE
Output will appear here.

Use type() to inspect the decimal number 3.14.

EXERCISE
Output will appear here.

Pause after running the example and explain each line in your own words. Notice what the program reads, what it stores, and what it prints, then make one small change and run it again to see exactly what changed.

Practice

Work through the same idea a few times so it starts to feel familiar. Begin by copying the example, then make the single change the instruction asks for, and finally explain to yourself why the result changed.

Type `print(type(42))` and run it.
EXERCISE
Output will appear here.
Replace `42` with `"42"` and run again.
EXERCISE
Output will appear here.
Predict which type `3.14` has before running it.
EXERCISE
Output will appear here.
Print the types of one string, one whole number, and one boolean.
EXERCISE
Output will appear here.
A nineteenth-century astronomical atlas plate with stars and celestial forms
Bilder-Atlas der Sternenwelt, Plate 32 · Edmund Weiss, via Artvee

Variables

Variables give useful names to values, so we can use them again later. This is one of the main ideas in programming: instead of repeating the same thing over and over, give it a label and refer back to it.

Think of a variable as a label on a box. The label is what you write in code, and the value is what the label points to. When the value changes, the name stays the same unless you assign something new to it.

name = "Ada"
print(name)

Store two details, then print them together. This shows that a program can combine separate pieces of information into one sentence or one result.

EXAMPLE
Output will appear here.

Create a variable named city, give it a value, and print it.

EXERCISE
Output will appear here.

Pause after running the example and explain each line in your own words. Notice what the program reads, what it stores, and what it prints, then make one small change and run it again to see exactly what changed.

Practice

Work through the same idea a few times so it starts to feel familiar. Begin by copying the example, then make the single change the instruction asks for, and finally explain to yourself why the result changed.

Type `city = "Lima"` and `print(city)`.
EXERCISE
Output will appear here.
Change only the value from `Lima` to another city.
EXERCISE
Output will appear here.
Predict what prints after `city = "Oslo"` followed by `city = "Lima"`.
EXERCISE
Output will appear here.
Create `name` and `year` variables, then print both.
EXERCISE
Output will appear here.
A botanical illustration of a pink rose
Rosa Indica Subviolacea · Pierre-Joseph Redouté, via Artvee

Strings

Strings are text, and text is the easiest place to start practicing with real program output. Once you can store and change text, you can build prompts, labels, messages, and user-facing responses.

F-strings let us place a variable directly inside a sentence. They are useful because they keep the final message readable without needing to join many small pieces together.

name = "Sam"
message = f"Welcome, {name}!"

Use a string method to change text to uppercase. Methods are little actions attached to a value, and this is your first chance to see how Python can transform text without replacing the original idea.

EXAMPLE
Output will appear here.

Make a variable named food and print it in uppercase.

EXERCISE
Output will appear here.

Pause after running the example and explain each line in your own words. Notice what the program reads, what it stores, and what it prints, then make one small change and run it again to see exactly what changed.

Practice

Work through the same idea a few times so it starts to feel familiar. Begin by copying the example, then make the single change the instruction asks for, and finally explain to yourself why the result changed.

Type `word = "hello"` and `print(word.upper())`.
EXERCISE
Output will appear here.
Change `hello` to a word with mixed capital letters.
EXERCISE
Output will appear here.
Predict the output of `print("code".upper())`.
EXERCISE
Output will appear here.
Store a food in `food` and print it in uppercase.
EXERCISE
Output will appear here.

Lists

Lists keep ordered items together. They are useful when the order matters, when you want to walk through several values, or when you want to add and remove items over time.

The first item has position 0, which can feel strange at first. That numbering choice is common in programming, so it is worth getting comfortable with it early.

colors = ["red", "blue"]
first_color = colors[0]

Add an item to the end of a list with append(). This is a common pattern when you are collecting results step by step instead of writing the whole list at once.

EXAMPLE
Output will appear here.

Create a list of two animals, append one more animal, then print the list.

EXERCISE
Output will appear here.

Pause after running the example and explain each line in your own words. Notice what the program reads, what it stores, and what it prints, then make one small change and run it again to see exactly what changed.

Practice

Work through the same idea a few times so it starts to feel familiar. Begin by copying the example, then make the single change the instruction asks for, and finally explain to yourself why the result changed.

Type `colors = ["red", "blue"]` and `print(colors[0])`.
EXERCISE
Output will appear here.
Replace `colors[0]` with `colors[1]`.
EXERCISE
Output will appear here.
Predict what index `2` does in a two-item list.
EXERCISE
Output will appear here.
Make a list of three animals and print the last one.
EXERCISE
Output will appear here.
A historical botanical illustration of an eggplant
The Egg Plant · Robert John Thornton, via Artvee

Dictionaries

Dictionaries store related values under descriptive keys instead of positions. This makes them a strong fit when you already know the name of the thing you want and do not want to count through a list to find it.

You can think of a dictionary like a small lookup table. The key is what you ask for, and the value is what you get back.

profile = {"name": "Maya"}
print(profile["name"])

Add a new key and value to a dictionary. This shows that dictionaries are not fixed structures; you can expand them as your program learns more information.

EXAMPLE
Output will appear here.

Create a dictionary for a book with a title key, then print its title.

EXERCISE
Output will appear here.

Pause after running the example and explain each line in your own words. Notice what the program reads, what it stores, and what it prints, then make one small change and run it again to see exactly what changed.

Practice

Work through the same idea a few times so it starts to feel familiar. Begin by copying the example, then make the single change the instruction asks for, and finally explain to yourself why the result changed.

Type `person = {"name": "Ari"}` and `print(person["name"])`.
EXERCISE
Output will appear here.
Change the stored name without changing the key.
EXERCISE
Output will appear here.
Predict what happens when you ask for `person["age"]`.
EXERCISE
Output will appear here.
Create a dictionary with `name` and `city`, then print the city.
EXERCISE
Output will appear here.