← all tutorials

Your first 10 lines of Python

Forget “hello world” as a ritual. Let’s write ten lines that actually show you how Python thinks — and explain every one.

Lines 1–3: variables

name = "Sam"
age = 34
city = "Manchester"

A variable is just a labelled box. name = "Sam" puts the text "Sam" in a box labelled name. Text goes in quotes (Python calls it a string); numbers don’t.

Lines 4–5: printing

print(name)
print(age)

print() shows whatever you give it. Run these and you’ll see Sam and 34. That’s the whole feedback loop of programming: change something, run it, look at what happened.

Lines 6–7: f-strings

print(f"{name} is {age} years old.")
print(f"Next year, {name} will be {age + 1}.")

An f-string is a sentence with holes in it. Put f before the quotes, and anything inside {curly braces} gets swapped for its value — even a calculation, like {age + 1}. This is the modern way Python developers write output, so you’re learning the real habit from day one.

Lines 8–10: making a decision

if age >= 18:
    print(f"{name} can vote.")
print("Done!")

if asks a question. If the answer is yes, the indented line runs; if not, Python skips it. The indentation isn’t decoration — it’s how Python knows which lines belong to the if. The last line isn’t indented, so it always runs.

What you just learned

Variables, strings, printing, f-strings, a calculation, and a decision — in ten lines. That’s a genuine chunk of the foundations. Next up: lists and loops, where Python starts doing the repetitive work for you.

Try it yourself

main.pyPython 3 · in your browser
You can't break anything.