Pebellslearn by building
0%
RoadmapMatrixCatalogSandboxSign in
Fundamentals  ›  Lesson

Basic Syntax & Output

Basic Syntax 10 minHow Python code is written and how to produce output
You're building a piece ofBill Splitter & Tip Calculator
This piece — greet_customer(): Greets each guest at the very top of the app.
Scenario A party of 4 sits down at Table 12. The app greets them by name before they start ordering.
Your task
Build greet_customer(name). It returns the welcome line the app shows each guest. Example: greet_customer("Ada") → "Welcome, Ada! Let's split the bill.".

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.

python

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:

python

print() is how your program talks

python

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:

python

Try it: change sep="-" to sep="/" and Run.


Text lives in quotes

Single and double quotes do exactly the same job:

python

Until your text contains an apostrophe. Then the quote style suddenly matters a great deal — run this, read the error, and fix it:

broken — fix itSyntaxError

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

python

+ only joins text to text, though. A number is not text, and Python refuses to guess what you meant:

broken — fix itTypeError

Run 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}:

python

You can do arithmetic and formatting inside the braces too:

python

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:

python

For text that spans lines, triple quotes keep the breaks exactly as you typed them:

python

print vs return — the one that catches everyone

This is the heart of today's task, so let's be precise:

  • print(x) shows x to a human. It hands nothing back to your program.
  • return x gives x back 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?

What does this print?
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.

python

Step through it and watch result come into existence at the moment the function returns:

step through it
1def shout(word):
2 loud = word.upper()
3 return loud + "!"
4 
5result = shout("hello")
6print(result)

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 function

Two smaller rules worth knowing now. Python is case-sensitive, so name and Name are two different variables:

What does this print?
name = "Ada"
Name = "Bea"
print(name)

And if a line gets too long, a trailing backslash continues it onto the next:

python

🎯 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. ✅

greet_customer.py
Call the function you wrote — just like your app's frontend would. Edit the inputs and hit Call.
greet_customer(name) → strReturn a friendly welcome line for the guest.
try:
returned
Press Run to execute your code.
Press Check to run the tests for this lesson.