Your first script
Write a file, run it and read what Python answers.
hello.py, run it from the terminal and see it print a message that uses a variable.
Why start here
Your goal is a program that goes to the web for you: downloads a page, queries an API and saves the result. That program will be a script: a text file with instructions that Python runs one after another, from top to bottom. Before bringing anything in from the internet you need to master the basic cycle: write, run, read the result.
Three ideas
1. print() shows something on screen
The text goes between quotes. Without quotes, Python thinks you mean a name.
print("Hello, world")
# Hello, world
2. A variable is a name with a stored value
The = sign doesn't compare: it stores the value on the right under the name on the left. If you store it again, the previous value is lost.1
name = "Ana"
print("Hello, " + name)
# Hello, Ana
name = "Luis"
print("Hello, " + name)
# Hello, Luis
print("name")
# name (with quotes it's just the word, not the variable)
The + sign between two texts joins them. Notice the space inside "Hello, ": Python doesn't add spaces for you.
3. Errors are information, not failures
Python stops and tells you which line failed and why. The book sums it up with a title: "Errors Are Okay!".1 For example, if you forget to close the quotes:
print("Hello)
print("Hello)
^
SyntaxError: unterminated string literal (detected at line 1)
The ^ points to where the text that was never closed begins. Learning to read these messages will save you more time than any other skill today.
Do it yourself
These steps assume macOS and Python already installed (on your machine it's python3, version 3.14).
- Open the Terminal app. Check that Python responds:
python3 --version - Go into the course folder and create a folder to practice in:
cd ~/minicurso-python-teach mkdir practice cd practice - Create the file with a plain text editor (VS Code, or
nano hello.pyin the terminal; withnanoyou save with Ctrl+O, Enter and exit with Ctrl+X). Type:your_name = "type your name here" print("Hello, " + your_name) print("Today I start learning Python") - Run it:
python3 hello.py - Break it on purpose. Delete the closing quotes of the first line, run it again and read the error. Then fix it.
Check what you remember
Answer without looking above. If you get it wrong, that's a good sign: the effort of recalling is what makes learning stick.
What does this program show? Type exactly what appears on screen.
city = "Lima"
city = "Quito"
print(city)
The second line stores "Quito" in city and the value "Lima" is lost.
Given these two lines, what does the third one do?
name = "Ana"
print("name")
With quotes it's just text. Without quotes, print(name) would show Ana.
You run print("Hello) and Python answers SyntaxError: unterminated string literal. What's going on?
"Unterminated string literal" means unfinished text: the quotes were opened and never closed.
Main source
Read Chapter 1: Python Basics of Automate the Boring Stuff with Python (Al Sweigart, free online).
Today you only need these sections: Errors Are Okay!, Storing Values in Variables and Your First Program.
The rest of the chapter (numbers, input(), len()) will be lesson 2.
To look up the language, there's the official tutorial.
Remember: your teacher is the agent you're talking to. If an error doesn't make sense, if a step fails on your machine or if anything in this lesson was unclear, ask it. Paste the complete error message; it's the most useful thing you can give it.
Syntax summary to keep at hand: Reference: Python basics.