Basic Syntax & Output
Welcome to your first real Python. By the end of this section you'll have built a working Bill Splitter & Tip Calculator — a real app with a real interface (see the 🗺 App Map tab). Every lesson adds one working piece. This one builds the welcome banner.
First, though, the raw materials of every Python program: comments, output, and text. Poke at the boxes below. Change the words. Break them on purpose — there's a Reset button, and breaking things is genuinely how this sticks.
Comments are notes to humans
Anything after a # is ignored by Python entirely. It's there for whoever reads
the code next — often you, three weeks later.
For a longer note, wrap it in triple quotes. Strictly this is a string that nobody uses, but everyone treats it as a block comment:
print() is how your program talks
Hand print several values separated by commas and it puts a space between them.
sep= changes that separator, end= changes what goes on the end instead of a
new line:
Try it: change
sep="-"tosep="/"and Run.
Text lives in quotes
Single and double quotes do exactly the same job:
Until your text contains an apostrophe. Then the quote style suddenly matters a great deal — run this, read the error, and fix it:
SyntaxErrorThis won't even start. Run it, read the error, then get it to print the sentence.
That error arrives before anything runs — Python couldn't even finish reading
your program. A SyntaxError always means "I couldn't parse this", never "this
went wrong while running".
Gluing text together
+ joins strings end to end. It joins exactly what you give it, so you supply
your own spaces:
+ only joins text to text, though. A number is not text, and Python refuses to
guess what you meant:
TypeErrorRun it and read the error — then make it print "Table 12".
Some languages quietly convert the number for you. Python's refusal is
deliberate: "3" + 4 could plausibly be "34" or 7, and guessing wrong
silently is worse than stopping.
f-strings, the good way
Concatenation gets clumsy fast. Put an f before the quote and you can drop
variables straight into {braces}:
You can do arithmetic and formatting inside the braces too:
You'll reach for f-strings constantly — they're the clearest way to build text that has values in it.
Escapes and multi-line text
Inside a string, a backslash starts an escape sequence. \n is a new line,
\t is a tab:
For text that spans lines, triple quotes keep the breaks exactly as you typed them:
print vs return — the one that catches everyone
This is the heart of today's task, so let's be precise:
print(x)showsxto a human. It hands nothing back to your program.return xgivesxback to whoever called the function.
Our app needs the greeting value so it can put it on screen. So we return it.
What happens if you forget?
def shout(word):
word.upper() + "!"
print(shout("hello"))That None is the single most common bug in a beginner's first week. The function
did the work — it just never gave it back.
Step through it and watch result come into existence at the moment the function
returns:
Indentation is the structure
Python has no { }. The indented lines are the ones inside the function —
four spaces, by convention.
def greet_customer(name):
return f"Welcome, {name}!" # indented -> inside the functionTwo smaller rules worth knowing now. Python is case-sensitive, so name and
Name are two different variables:
name = "Ada"
Name = "Bea"
print(name)And if a line gets too long, a trailing backslash continues it onto the next:
🎯 Your turn
Write greet_customer(name) — it returns the welcome line the app shows each
guest:
greet_customer("Ada")→"Welcome, Ada! Let's split the bill."greet_customer("Sam")→"Welcome, Sam! Let's split the bill."
Hint — reach for an f-string, and return the value — don't print it.
Then press ▶ Run, tap the Live App try chips to call it with different inputs, and hit ✓ Check. Green = this piece of the app is built. ✅
