🐍 Python for Everyone

← Back to all chapters

Chapter 1 of 18 Beginner 12 min read

Your First Python Program

No experience needed. No installs required to start reading — just bring your curiosity.

Imagine you could give a computer instructions in plain steps, and it would follow them exactly, every single time, without getting tired or bored. That's what programming is. And Python is one of the friendliest languages ever made for doing it. To make this chapter's examples feel like a real, connected program instead of a pile of disconnected snippets, we'll build up one tiny project together, one instruction at a time: a little "Corner Cafe" greeter that welcomes a customer, remembers their order, and prints them a receipt — using their own name.

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.

What is... Python? Python is a programming language — a way of writing instructions that a computer can run. It's known for reading almost like plain English, which is why it's often recommended as a first language for total beginners, while also being powerful enough to run real companies like Instagram, Spotify, and NASA's data pipelines.

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().

hello.py
print("Hello, world!")

Run that one line, and Python will display:

Output
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:

print
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.
What is... a function? A function is a named, reusable set of instructions that does one job. You don't need to know how 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.
What is... a string? Any piece of text wrapped in quotation marks (single '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.

cafe.py
print("Welcome to Corner Cafe!")
Output
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.

cafe.py
customer = "Maya"
print(customer)
Output
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 customer here. That's on purpose: without quotes, Python looks up the variable called customer and prints whatever is stored inside it (Maya). With quotes, print("customer") would just print the literal word "customer."
What is... a variable? A variable is a name that points to a value stored in the computer's memory. Think of a variable as a labeled jar: 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.

cafe.py
order = "Latte"     # a string (text)
cups = 2            # an integer (a whole number)
price = 4.5         # a float (a number with a decimal point)
What is... a data type? A data type tells Python what kind of value something is, so it knows what you're allowed to do with it. You can add two numbers together (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.

cafe.py
customer = input("Welcome to Corner Cafe! What's your name? ")
print("Nice to meet you, " + customer + "!")
Output (typed reply: 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."
What is... concatenation? Concatenation just means joining pieces of text together into one. If 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():

fix_type_error.py
price = 4
print("Your total is $" + str(price))
Output
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:

cafe.py
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!")
Output (typed replies: 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.

In the Real World

Points to Remember

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.

← All Chapters Take the Quiz →