Intro to Python — Your First Real Program
Install Python, meet the REPL, and write a program that takes input from a human and does something useful with it — all in one sitting.
Most "learn to code" guides spend twenty minutes on history before you type anything. We are going to have working code on your screen in about four.
Here is the deal: Python is the language that gets out of your way. No semicolons, no curly braces, no compiler yelling at you about types you have not learned yet. You write what you mean, and it runs.
#What you need
Nothing but a computer and ten minutes. No paid tools, no accounts.
#Step 1 — Install Python
Go to python.org/downloads and grab the latest version for your operating system.
On macOS, the installer just works. On Linux, Python is almost certainly already there.
Now open your terminal — Command Prompt or PowerShell on Windows, Terminal on macOS and Linux — and ask Python to identify itself:
python --versionYou should see something like Python 3.13.1. If you get "command not found", try python3 --version instead. On macOS and most Linux systems, python3 is the correct name.
#Step 2 — Say hello from the REPL
Type python on its own and hit enter. The prompt changes to >>>. You are now inside the REPL — Read, Eval, Print, Loop. It reads a line, evaluates it, prints the answer, and loops back for more.
>>> print("Hello, world!")
Hello, world!
>>> 2 + 2
4
>>> "Dom" * 3
'DomDomDom'That last one is not a typo. Multiplying a string by a number repeats it. Python is full of small, sensible surprises like that.
The REPL is your scratchpad forever. Any time you are unsure what a piece of code does, you paste it in here rather than guessing. Type exit() to leave.
#Step 3 — Your first real file
The REPL forgets everything when you close it. Real programs live in files.
Make a file called hello.py — in VS Code, Notepad, or whatever you have — and put this inside:
print("Hello, world!")
print("This is my first Python program.")Save it, then in the terminal, navigate to that folder and run:
python hello.pyBoth lines print, in order, top to bottom. That is the whole execution model: Python starts at line one and works down. Everything else you will ever learn is a way of changing what happens on the way.
#Step 4 — Variables are labels, not boxes
A variable is a name pointing at a value.
name = "Dom"
subscribers = 119
average_rating = 4.8
is_free = TrueNo String name, no int subscribers. Python figures out the type from the value. That is called dynamic typing, and it is why Python code is so short.
Four types just showed up, and they cover most of what you will use:
| Type | Example | What it holds |
|---|---|---|
str | "Dom" | Text, in single or double quotes |
int | 119 | Whole numbers |
float | 4.8 | Decimals |
bool | True / False | Yes or no — note the capital letter |
You can always ask what something is:
>>> type(subscribers)
<class 'int'>#Naming rules that keep you out of trouble
- Use
snake_case:total_score, nottotalScoreorTotalScore. - Start with a letter or underscore, never a digit.
- Names are case-sensitive —
scoreandScoreare two different variables. - Do not name things
list,str,sum, ortype. Those are built-in functions, and shadowing them breaks code in ways that are genuinely hard to debug.
#Step 5 — f-strings, the only way you should build text
You will constantly need to drop a variable into a sentence. Python has three ways to do it, and only one is worth learning:
name = "Dom"
videos = 15
print(f"{name} has published {videos} videos.")Note the f before the opening quote. That is what makes the curly braces special. Output:
Dom has published 15 videos.You can run real expressions inside the braces:
print(f"That is roughly {videos / 5:.1f} videos per track.")That is roughly 3.0 videos per track.The :.1f after the expression is a format spec — "render this float with one decimal place." Handy for money and percentages.
#Step 6 — Talk to the human
input() pauses the program, waits for someone to type something, and hands it back as a string.
name = input("What is your name? ")
print(f"Nice to meet you, {name}.")Now the important part, and the source of about a third of all beginner bugs:
Watch it go wrong:
age = input("How old are you? ") # user types 30
print(age + 10) # TypeError!The fix is to convert explicitly:
age = int(input("How old are you? "))
print(f"In ten years you will be {age + 10}.")int(), float() and str() convert between types. Use them the moment the value arrives, not fifty lines later.
#Step 7 — Make a decision
score = int(input("Enter your score: "))
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C")
else:
print("Keep going — let us review together.")Two things to notice.
The colon and the indentation are the syntax. Other languages use { and } to say "this block belongs to the if." Python uses indentation, and it is not optional styling — it is the actual structure of the program. Four spaces per level. Your editor will do it for you if you let it.
elif is only checked if everything above it failed. Order matters. If you put score >= 70 first, a score of 95 would print "Grade: C", because that check passes too and Python stops at the first match.
#Put it together
Save this as greeter.py and run it:
print("=" * 32)
print(" Coding with Dom — Lesson 1")
print("=" * 32)
name = input("What should I call you? ")
years = int(input("How many years have you been coding? "))
if years == 0:
level = "you are starting today, which is the best time"
elif years < 2:
level = "you are past the hardest part"
else:
level = "you are dangerous already"
print()
print(f"Welcome, {name}.")
print(f"With {years} year(s) in, {level}.")
print(f"Next lesson unlocks in {3 - min(years, 3)} steps. Let us go.")Every idea from this lesson is in there: strings, ints, input(), conversion, f-strings, and a branch. Thirteen lines, and it is a real program.
Check yourself
3 questions on what you just read. No score is kept — it is only here to catch the bits that did not stick.
-
1A user types
30at aninput()prompt. What is the type of the value your program receives?Show the answer
A.
str— always, no exceptions.input()hands back a string every single time. Wrap it inint()orfloat()the moment it arrives, orage + 10raises a TypeError. -
2Which of these prints
Videos: 15whenvideos = 15?Show the answer
A.
print(f"Videos: {videos}")The
fprefix is what makes the braces special, and the variable has to be inside them. Miss either piece and you print the literal text. -
3Why does this print
Grade: Cfor a score of95?Show the answer
A.
elifis only tested when every branch above it fails, and95 >= 70already passed.Order matters in a chain. Put the narrowest condition first, or the broad one swallows everything.
#Key takeaways
- Python runs top to bottom; indentation defines structure.
- Variables are names bound to values — no type declarations needed.
input()always hands you a string. Convert it immediately withint()orfloat().- f-strings (
f"...") are the correct way to build text out of variables. - The REPL is not a toy. Use it every time you are unsure what something does.
Next up: the data structures that let you handle more than one thing at a time.
Finished this one?
The challenge above has no posted solution — that is deliberate. Get it working, then come back for the next lesson.