Your First Python Program
No experience needed. No installs required to start reading — just bring your curiosity.
1. What is a "program," really?
A program is just a list of instructions, written in an order the computer can understand, that tells it what to do — step by step, top to bottom.
Think of it like the little routine behind a coffee shop counter: "greet the customer," "take their order," "print the receipt." Nobody skips a step or does them out of order — and neither does a computer. A program is the same idea, except the "counter" is the computer, and the "ingredients" are things like text, numbers, and questions you ask the user.
2. Your first instruction: print()
The very first thing most people learn in any language is how to make the
computer say something back. In Python, that's done with print().
print("Hello, world!")
Run that one line, and Python will display:
Hello, world!
Thought process: this is the smallest possible Python program, so the "thought process" is really about picking the exact right first example — one line, one built-in function, one visible result — so a total beginner can run it and see cause and effect immediately, before anything else is layered on.
Write the prompt you'd give an AI assistant to build this:
Show a strong version of this prompt
Write the simplest possible Python program: a single line that uses the built-in print() function to display the text "Hello, world!" exactly, including the exclamation mark. Don't use any variables, input, or other functions — just one call to print() with a string literal.
Let's break down exactly what's happening in that line:
- This is a built-in Python function — a reusable command that does one specific job. This one's job is: "display whatever I'm given, on the screen."
- ( )
- Parentheses are how you hand information to a function. Whatever goes inside the parentheses is what gets displayed.
- "Hello, world!"
- The quotation marks tell Python "this is text, not an instruction to run." Anything wrapped in quotes is treated as plain text, exactly as typed.
print() works internally — you just
need to know what to hand it and what it will do. That's the whole point of a
function: it hides the complicated part behind a simple name.
'like this' or
double "like this") is called a string in
programming. It's called that because it's a "string of characters" lined up
in a row. "Hello, world!" is a string. So is "42" —
even though it looks like a number, the quotes make it text.
print() works with any string you hand it — not just
"Hello, world!". Here's the line that will open our little
project for this chapter: a welcome message for a corner coffee shop.
print("Welcome to Corner Cafe!")
Welcome to Corner Cafe!
Thought process: swapping the string inside print() for a business-specific greeting is the whole exercise here — the point is recognizing that print() doesn't care what text you give it, so the "thought process" a beginner should practice is just: what exact words does this cafe want its customers to see first?
Write the prompt you'd give an AI assistant to build this:
Show a strong version of this prompt
Write a single-line Python program using print() that displays the exact text "Welcome to Corner Cafe!" (with the exclamation mark, no extra punctuation). Save it as cafe.py — we'll keep adding to this same file as the program grows.
Same print(), same idea — just a different string. We'll
keep adding to this cafe.py program for the rest of the chapter.
3. Storing information: variables
A fixed welcome message is nice, but a real coffee shop needs to remember things about the customer in front of it — a name, an order, a price. Typing that message over and over for every customer would get old fast, and it wouldn't be personal.
That's what a variable is for: a labeled box where you can store a piece of information and use it later.
customer = "Maya"
print(customer)
Maya
- customer
- This is the variable's name — the label on the box. You can call it almost anything (avoid spaces and starting with a number).
- =
- In Python, a single equals sign means "store this value in this box," not "is equal to" like in math class. This trips up a lot of beginners — keep it in mind!
- "Maya"
- The value being stored — a string, in this case.
- print(customer)
- Notice there are no quotes around
customerhere. That's on purpose: without quotes, Python looks up the variable calledcustomerand prints whatever is stored inside it (Maya). With quotes,print("customer")would just print the literal word "customer."
customer = "Maya" is like
writing "customer" on a jar's label and putting the note "Maya" inside it.
Whenever you use the label later, Python fetches whatever is currently inside
the jar.
4. Basic types: text vs. numbers
Not everything you store is text. Python understands a few basic types of information, and the two you'll use constantly as a beginner are strings (text) and numbers.
Our cafe.py program needs both: an order is text, but how many
cups and what they cost are numbers.
order = "Latte" # a string (text)
cups = 2 # an integer (a whole number)
price = 4.5 # a float (a number with a decimal point)
2 + 2), but adding two pieces of text works differently (it joins
them, rather than doing math). The three types you'll meet most as a beginner:
string (text, in quotes), int (a whole
number, no decimal point), and float (a number with a decimal
point).
5. Asking the user a question: input()
So far, our programs have only said things to the person running them.
input() lets a program ask a question and wait for a reply
— this is what makes a program feel alive and personal, instead of just a
fixed message.
customer = input("Welcome to Corner Cafe! What's your name? ")
print("Nice to meet you, " + customer + "!")
Maya)
Welcome to Corner Cafe! What's your name? Nice to meet you, Maya!
- input("Welcome to Corner Cafe! What's your name? ")
- This displays the question on screen, then pauses the program completely until the person types something and presses Enter.
- customer = input(...)
- Whatever the person typed gets stored in the variable
customer— exactly like storing any other value, except this one came from the user instead of being written directly in the code. - "Nice to meet you, " + customer + "!"
- The
+symbol here glues strings together, end to end. This is called concatenation — a fancy word for "joining text pieces into one longer piece."
first = "Py" and second = "thon", then
first + second produces "Python". It's the text
equivalent of pushing two puzzle pieces together.
Go Deeper: why can't I add a number and a string with +?
If you try print("Your total is $" + 4), Python will raise an
error, because + means two different things depending on type:
for numbers it means "add," for strings it means "join." Python refuses to
guess which one you meant when the types don't match. To fix it, convert the
number to a string first, using str():
price = 4
print("Your total is $" + str(price))
Your total is $4
str(price) takes the number 4 and produces the
text "4", which can then be safely joined with other text.
This "convert one type into another on purpose" pattern is extremely common
in real Python code and is worth getting comfortable with early.
6. Putting it all together
Here's the finished cafe.py — the same little coffee shop
program we've been building all chapter, now taking a real order and printing
a receipt using everything you've learned:
customer = input("Welcome to Corner Cafe! What's your name? ")
order = input("What would you like to order? ")
print("Order for " + customer + ": " + order + ".")
print("Thanks for stopping by, " + customer + " - enjoy!")
Maya, then a cappuccino)
Welcome to Corner Cafe! What's your name? What would you like to order? Order for Maya: a cappuccino.
Thanks for stopping by, Maya - enjoy!
Try running this yourself. Every time you run it, it can produce a different, personal result — because it's not printing fixed text anymore, it's printing your answers back to you, just like a real cafe greeting a real customer.
- Every command-line tool you've ever used —
git,pip,docker— is built on exactly this: reading input, printing output. - Server logs (the diagnostic text engineers read when something breaks in production) are just millions of
print()-style statements, timestamped. - The very first thing engineers do when learning any new tool or API is write a tiny script like today's — it's not a "beginner" pattern, it's the universal first move.
Points to Remember
print()displays something on the screen.- Text wrapped in quotes is called a string.
- A single
=stores a value in a variable — it does not mean mathematical equality. - Numbers without decimals are integers; numbers with decimals are floats.
input()asks the user a question and waits for their typed reply, storing it in a variable.+joins ("concatenates") strings together; joining a string with a number directly causes an error unless you convert the number withstr()first.
Ready to check what stuck? Head to the interactive quiz next — every blank has a Check button, so you'll know instantly if you've got it.