Python From Zero: The First 10 Concepts
⚠️ Version note: this uses Python 3 (any 3.x). The interpreter and the browser sandboxes named here change occasionally; the language basics below have been stable for years. Last checked: 24 July 2026.
Code is just instructions, written precisely
People think programming is about being good at maths, or being clever. It isn't. It's about being able to say exactly what you mean, in order, to something that does precisely what you say and nothing you assumed.
That last part is the whole difficulty and also the whole skill. A computer has no common sense. It won't guess what you meant. Every bug you'll ever write is a gap between what you said and what you meant — and learning to code is really learning to notice that gap.
Python is the best first language for a specific reason: it reads almost like English, so the distance between the idea and the code is small. You spend your attention on the logic, not on punctuation.
if temperature > 30: print("hot")— you can read that out loud and it means what it says.
Ten concepts cover most of what any program does. This lesson is those ten, each one run by you.
What you'll have at the end
- Python running (or a browser sandbox — either works)
- The ten building blocks every program is made of
- A real program you wrote: input → decision → output
- The habit of reading an error instead of fearing it
Get Python running (5 min)
Two options. Either is fine to start.
Fastest — a browser sandbox. Go to any online Python runner (search "python online"), or use the one embedded in this lesson. Nothing to install. Perfect for the first ten concepts.
Proper — install it. Download from python.org, or on Mac it's often already there
(python3 --version in the Terminal — see TC-03). You'll want this eventually; the sandbox is
fine for now.
✅ Check: you can run print("hello") and see hello appear.
Variables: named boxes (8 min)
A variable is a name pointing at a value. You make one by assigning:
name = "Sam"
age = 17
height = 1.75
is_student = TrueThe name is on the left, the value on the right, = means "put this in that". After this, name
is "Sam" everywhere you use it.
print(name) # Sam
print("Hi " + name) # Hi Sam
age = age + 1 # now age is 18 — the right side runs firstNames describe the thing. age, not x. total_price, not t. Code is read far more often than
written, and future-you is one of the readers. Good names are half of readable code.
✅ Check: you've made three variables and printed a sentence built from them.
The four types you'll use constantly (8 min)
Every value has a type, and the type decides what you can do with it.
text = "hello" # str — text, in quotes
whole = 42 # int — whole number
decimal = 3.14 # float — decimal number
yes_no = True # bool — True or False onlyThe type matters because operations mean different things:
"5" + "5" # "55" — joining text
5 + 5 # 10 — adding numbers
"5" + 5 # ERROR — you can't add text to a numberThat last one is one of the most common beginner errors, and it has a name you'll meet: TypeError.
When it appears, you've mixed text and numbers. Convert between them:
int("5") # 5 — text to whole number
str(5) # "5" — number to text
float("3.14") # 3.14 — text to decimalThis matters immediately because input always arrives as text — even when it's digits.
✅ Check: you've triggered a TypeError on purpose by adding text to a number, then fixed it with
int().
Input and output: talking to a person (6 min)
name = input("What's your name? ")
print("Hello, " + name)input() stops and waits for the person to type, then hands back what they typed, as text. That
"as text" is the catch:
age = input("Your age? ") # age is the STRING "17", not the number 17
age = int(age) # NOW it's the number 17
next_year = age + 1 # worksForget the int() and age + 1 fails, because you're trying to add a number to text. This trips up
everyone once. Input is always a string; convert it before doing maths.
✅ Check: you've asked for a number, converted it, and done arithmetic with it.
Making decisions: if / elif / else (12 min)
This is where a program stops being a calculator and starts having behaviour.
temperature = int(input("Temperature? "))
if temperature > 30:
print("Too hot")
elif temperature < 10:
print("Too cold")
else:
print("Fine")Read it aloud — it means exactly what it says. Three things to notice, because they're where beginners stumble:
- The colon
:ends everyif,elif,elseline. Forget it and Python complains. - The indentation is not decoration — it's the grammar. The indented lines are "what happens if this is true". Python uses indentation the way other languages use brackets. Four spaces, consistent. Mixing tabs and spaces is a classic invisible bug.
==compares,=assigns.if age == 18:asks "is age 18?".age = 18sets it. Using=where you meant==is a rite of passage.
The comparison operators:
== equal to != not equal
> greater < less than
>= at least <= at most
and or not combine conditions:if age >= 13 and age <= 19:
print("teenager")✅ Check: you've written an if/elif/else that gives three different outputs for three
different inputs.
Lists: many things in one name (10 min)
A list holds an ordered collection:
scores = [72, 85, 90, 68]
names = ["Sam", "Alex", "Jo"]You reach items by position, counting from zero (the thing that feels wrong for a week and then never again):
scores[0] # 72 — the FIRST item
scores[1] # 85
scores[-1] # 68 — the LAST item (negative counts from the end)Do things to lists:
scores.append(95) # add to the end → [72, 85, 90, 68, 95]
len(scores) # 5 — how many
sum(scores) # total
max(scores) # biggest
scores.sort() # rearrange smallest to largestCounting from zero is the single most common early confusion. The first item is [0], so a list
of 5 items has indices 0 to 4, and scores[5] is an error (IndexError). Once it clicks it's
permanent.
✅ Check: you've made a list, added to it, and printed its length and its first and last items.
Loops: doing something to each item (12 min)
The reason computers are useful: they repeat without getting bored.
scores = [72, 85, 90, 68]
for score in scores:
print(score)Read it as English: "for each score in scores, print it." The variable score takes each value in
turn. This runs the indented block once per item.
total = 0
for score in scores:
total = total + score
print("Total:", total)Counting a range when you want to repeat a set number of times:
for i in range(5): # i goes 0, 1, 2, 3, 4
print(i)
for i in range(1, 11): # 1 to 10
print(i)The while loop repeats as long as something stays true:
count = 3
while count > 0:
print(count)
count = count - 1 # ← MUST change, or it loops forever
print("Go!")⚠️ The infinite loop. If a
whilecondition never becomes false, the program runs forever. The fix is always the same: make sure something inside the loop moves toward the condition ending. If a program hangs, this is usually why — Ctrl-C stops it (TC-03).
✅ Check: you've looped over a list to compute a total, and used range() to repeat something a
fixed number of times.
Functions: name a chunk of logic (12 min)
When you do the same thing repeatedly, wrap it in a function — a named, reusable block.
def greet(name):
return "Hello, " + name
message = greet("Sam") # "Hello, Sam"
print(greet("Alex")) # "Hello, Alex"defstarts a definition, followed by the name and parameters in( )— the inputs.returnhands a value back to whoever called it.- You call it by name with real values in the brackets.
Why bother: write once, use everywhere, fix in one place. A calculation you need three times becomes one function called three times — and if it's wrong, you fix it once.
def is_teenager(age):
return age >= 13 and age <= 19
print(is_teenager(15)) # True
print(is_teenager(25)) # FalseA function should do one thing and its name should say what. is_teenager, calculate_total,
send_reminder. If you can't name it in a short phrase, it's probably doing too much.
✅ Check: you've written a function that takes an input, returns a result, and called it twice with different values.
Dictionaries: labelled data (8 min)
Lists use positions. Dictionaries use names (keys):
student = {
"name": "Sam",
"age": 17,
"grade": "A"
}
student["name"] # "Sam" — look up by key, not position
student["age"] = 18 # change a value
student["email"] = "…" # add a new keyUse a dictionary when each piece of data has a label: a person's details, a config, a count of
things. student["age"] reads far better than remembering that age is item [1] in a list.
✅ Check: you've made a dictionary, read a value by its key, and added a new key.
Errors are messages, not failures (8 min)
You will see red text constantly. This is normal, and the message is trying to help. Read the last line first — it names the error and usually the line number.
Traceback (most recent call last):
File "script.py", line 4
ValueError: invalid literal for int() with base 10: 'hello'That says: on line 4, you tried to int() something that wasn't a number ("hello"). The common ones:
| Error | Means | Usual cause |
|---|---|---|
SyntaxError | Python can't parse it | Missing :, unclosed ( or " |
IndentationError | Wrong indentation | Mixed tabs/spaces, or a block not indented |
NameError | Unknown name | Typo, or used a variable before defining it |
TypeError | Wrong types together | Text + number without converting |
ValueError | Right type, bad value | int("hello") |
IndexError | List position doesn't exist | scores[5] on a 5-item list |
KeyError | Dictionary key doesn't exist | student["phone"] when there's no phone |
The debugging habit: read the last line, find the line number, look at exactly that spot. Ninety per cent of errors are a typo, a missing colon, or a type mismatch — small, findable things, not mysteries.
✅ Check: you've deliberately caused two different errors, read the message, and fixed each from the message alone.
Put it together: a real program (15 min)
Everything so far, in one script. This is your output.
# A simple grade tracker
scores = []
print("Enter scores. Type 'done' to finish.")
while True:
entry = input("Score: ")
if entry == "done":
break # leave the loop
score = int(entry) # text → number
scores.append(score)
if len(scores) == 0:
print("No scores entered.")
else:
average = sum(scores) / len(scores)
print("Count: ", len(scores))
print("Average:", round(average, 1))
print("Highest:", max(scores))
if average >= 70:
print("Result: strong")
elif average >= 50:
print("Result: passing")
else:
print("Result: needs work")Look at what it uses: input, type conversion, a while loop, a list, append, break, if/elif/ else, built-in functions, and output. That's nine of the ten concepts working together — which is
what every program is: these blocks, combined for a purpose.
✅ Check: you've run this, entered a few scores, and got a correct average and result. Then changed one thing — a threshold, an extra output line — and confirmed your change worked.
Six common mistakes
- Forgetting
int()on input.input()is always text. Adding to it fails. =vs==. Assign vs compare. The classic.- Indentation errors. The indentation is the grammar. Four spaces, never mixed with tabs.
- Off-by-one / counting from zero. First item is
[0]; a 5-item list stops at[4]. - Infinite
whileloop. Something inside must move toward the condition ending. - Fearing the red text. The error message is the most useful thing on the screen. Read the last line.
Exercise (50 min, verifiable output)
Write a small program that's actually yours — pick one:
- Bill splitter: ask for a total and number of people, handle a tip, print each share.
- Study timer log: collect session lengths until "done", print total, average, and whether you hit a daily goal.
- Quiz: a list of questions, score the answers, print a percentage and a message.
Whichever you choose, it must use: input with conversion · a list · a loop · an if/elif/else · and at least one function you wrote.
Then break it on purpose: feed it bad input, read the error, and add a check that handles it.
✅ Finish check: a program that runs, takes real input, makes a decision, and produces correct output — containing input conversion, a list, a loop, a conditional, and your own function. Plus one error you caused and understood.
Cheatsheet
VARIABLES name = value (describe the thing: age, not x)
TYPES str "text" int 42 float 3.14 bool True/False
input() gives TEXT → int() / float() to do maths
DECISIONS if x > 10:
...
elif x > 5:
...
else:
...
== != > < >= <= and or not
(: ends the line · indentation is the grammar · == compares)
LISTS xs = [1, 2, 3] xs[0] first xs[-1] last (from 0!)
.append() len() sum() max() .sort()
LOOPS for x in xs: each item
for i in range(5): 0,1,2,3,4
while cond: ← something must change inside
FUNCTIONS def name(input):
return result
one job · name says what · call it: name(value)
DICTIONARIES d = {"key": value} d["key"] labelled data
ERRORS read the LAST line + line number. usually a typo,
a missing :, or a type mismatch.
SyntaxError IndentationError NameError TypeError
ValueError IndexError KeyErrorSources
- Python Software Foundation — The Python Tutorial
- Downey, A. — Think Python, 2015
- Sweigart, A. — Automate the Boring Stuff with Python, 2019
Next lesson: TC-05 — Your First Real Script (L2) Related: TC-03 The Terminal · TC-05 Automate Something You Do by Hand · AI-13 Build Your First Tool Without Knowing How to Code Path: Ship Your First Thing — 4/7 · AI Builder — 3/6