Session 1 of the universal Python Fundamentals series, covered in depth. It explains what a program is and how Python runs it from top to bottom, then covers print() in full: printing several values, the sep and end options, and blank lines. It goes on to strings with single and double quotes, quotes inside quotes, and the escape codes \n and \t, then joining with + and repeating with *, and comments. It ends with the two errors every beginner hits: missing quotes, which raises a NameError, and missing parentheses, which raises a SyntaxError. Every snippet and error message was copied verbatim from CPython 3.12.
Subject: Python Fundamentals · 103 slides · code lesson
Open the interactive version of this deck · Homework for this lesson
Title
Python Fundamentals - Session 1
What a program is, and making the computer talk back with print()
Objectives
A program is just written instructions a computer follows, one at a time. This first session gets you writing and reading real output. By the end you can:
print() to display text and numbers - alone, or several at once.sep, end, blank lines, and the escape codes \n and \t.+ and repeat them with *.# comments that explain your code.Section
Part 1
Concept
Writing code is writing a to-do list for the computer. Each line is one instruction.
The computer does not do anything you did not write. If it is not in your file, it does not happen.
statement — One complete instruction on one line, like print("hi"). A program is a stack of statements run in order.
Counterexample
Discussion prompt
Writing code is writing a to-do list for the computer. Each line is one instruction.
That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.
Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.
Answer:
The computer does not do anything you did not write. If it is not in your file, it does not happen.
Concept
Python starts at the first line of your file, does it, then moves to the next - down to the bottom, then stops.
Nothing runs out of order and nothing is skipped (until we learn if, which lets you skip on purpose). Order in the file is order of events.
Analogy
Discussion prompt
Explain Top to bottom, one line at a time by analogy to something with no Python Fundamentals in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.
Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.
Answer:
Python starts at the first line of your file, does it, then moves to the next - down to the bottom, then stops.
Intuition
Picture Python reading your file with a finger, one line at a time, never guessing what you meant.
It does exactly what each line says. If a line confuses it, it stops right there and tells you - it will not try to fix it for you.
That is why exact symbols matter: quotes, parentheses, spelling. Most of this session is really about being precise for a literal reader.
Explain it
Discussion prompt
Explain Python is a very literal reader to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.
Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.
Answer:
Picture Python reading your file with a finger, one line at a time, never guessing what you meant.
Concept
You write code into a file (ending in .py). Nothing happens yet - it is just text sitting there.
You run it to make Python actually do the instructions. In an editor that is usually a Run button; in a terminal it is python myfile.py.
Write, then run, then read the output. That loop is the whole job.
Concept
print(...) displays whatever you put in the parentheses on the screen. It is how a program shows you something.
It is the tool you will use in almost every program from here on - to show results and to peek at what your code is doing.
Section
Part 2
Concept
To print words, wrap them in quotes: print("Hello"). The quotes tell Python this is text to show, not code to run.
Single '...' or double "..." both work, as long as they match. We will mostly use double quotes.
Ranking
Put in order
Put the moves of Your first program into the order they have to happen.
Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. Python starts at the top. print puts the text between the quotes on the screen.
Worked example
Two instructions, run in order:
print("Hello, world!")
print("Learning Python.")Line 1 runs first and shows the first message
Why: Python starts at the top. print puts the text between the quotes on the screen.
Line 2 runs next, on its own line
Why: Each print() starts a fresh line, so the messages stack in order.
Read the output
Why: Verified by execution - the program prints these two lines in this order.
| line | runs | shows on screen |
|---|---|---|
| 1 | first | Hello, world! |
| 2 | second | Learning Python. |
Comparison
Comparison matrix
From Your first program: refill the runs column from what you know. The rest of the table is as it appeared.
| line | runs | shows on screen |
|---|---|---|
| 1 | first | Hello, world! |
| 2 | second | Learning Python. |
Concept
A number like 100 is printed without quotes: print(100). Quotes are only for text.
print("100") and print(100) look the same on screen, but one is text and one is a number - a difference that matters the moment you do math (next session).
Explain it to yourself
Discussion prompt
In Printing a number this move is made:
Bare numbers print as themselves
Why is that legal? Name the rule or definition it rests on before you read on.
Hint: If you can only say "because that is what you do", the rule is the thing to go and find.
Answer:
No quotes needed - 42 is a whole number, 3.5 has a decimal point.
Worked example
print(42)
print(3.5)Bare numbers print as themselves
Why: No quotes needed - 42 is a whole number, 3.5 has a decimal point.
Read the output
Why: Verified by execution.
| you write | shows |
|---|---|
| print(42) | 42 |
| print(3.5) | 3.5 |
Trade off
Comparison matrix
From Printing a number: every row here is a choice with a cost. Fill the shows column, then say which row you would actually pick and what you give up for it.
| you write | shows |
|---|---|
| print(42) | 42 |
| print(3.5) | 3.5 |
Concept
One print can show several things - just separate them with commas: print("Score:", 100).
print puts a single space between each item automatically, and converts numbers to text for you.
Explain it to yourself
Discussion prompt
In Mixing text and numbers this move is made:
Read the output
Why is that legal? Name the rule or definition it rests on before you read on.
Hint: If you can only say "because that is what you do", the rule is the thing to go and find.
Answer:
Verified by execution - note the space between the colon and 100 is added for you.
Worked example
print("Score:", 100)The comma lets one print show both pieces
Why: "Score:" is text and 100 is a number - print shows both with a space between.
Read the output
Why: Verified by execution - note the space between the colon and 100 is added for you.
| you write | shows |
|---|---|
| print("Score:", 100) | Score: 100 |
Blank canvas
Draw it
Draw what Mixing text and numbers just did — the shape of it, not the line-by-line working. One picture, labels only where you need them. Then check it against the steps: anything you could not draw is a step you followed rather than understood.
Pattern
Predict first
The table runs: "x =" | x = · 5 | 5 · "and y =" | and y = · 10 | 10
In More than two values, given the rows so far: what is the next one — the row where piece is whole line?
Correct: whole line | x = 5 and y = 10
| piece | shows as |
|---|---|
| "x =" | x = |
| 5 | 5 |
| "and y =" | and y = |
| 10 | 10 |
| whole line | x = 5 and y = 10 |
Why: The relationship between the columns, not the individual numbers, is what generates the next row. Text and numbers can alternate freely; each comma becomes one space on screen.
Worked example
print("x =", 5, "and y =", 10)Add as many comma-separated pieces as you like
Why: Text and numbers can alternate freely; each comma becomes one space on screen.
Read the output
Why: Verified by execution.
| piece | shows as |
|---|---|
| "x =" | x = |
| 5 | 5 |
| "and y =" | and y = |
| 10 | 10 |
| whole line | x = 5 and y = 10 |
Concept
After it shows its text, print moves the cursor to a new line. That is why two prints land on two lines.
So the number of print calls usually equals the number of lines on screen. (We will change that with end shortly.)
Worked example
print("A")
print("B")Each print finishes its own line
Why: print("A") shows A and ends the line; print("B") starts fresh below it.
Read the output
Why: Verified by execution: A and B on separate lines.
| line | shows |
|---|---|
| 1 | A |
| 2 | B |
Concept
print() with nothing inside prints nothing but a new line - a handy way to add space between blocks of output.
Worked example
print("Top")
print()
print("Bottom")The middle print() emits just a blank line
Why: Nothing to show, but it still ends a line - so a gap appears.
Read the output
Why: Verified by execution: Top, a blank line, then Bottom.
| line | shows |
|---|---|
| 1 | Top |
| 2 | (blank) |
| 3 | Bottom |
Error analysis
Annotate
Walk the callouts on Adding a blank line. Each one is a place this is easy to get subtly wrong.
Section
Part 3
Concept
By default print joins your comma-separated values with a space. sep="..." changes that separator to whatever you want.
sep="-" puts a dash between items; sep="" puts nothing at all.
Pattern
Predict first
The table runs: default (space) | 2024 07 15 · sep="-" | 2024-07-15
In Building a date with sep, given the rows so far: what is the next one — the row where setting is sep=""?
Correct: sep="" | 20240715
| setting | output |
|---|---|
| default (space) | 2024 07 15 |
| sep="-" | 2024-07-15 |
| sep="" | 20240715 |
Why: The relationship between the columns, not the individual numbers, is what generates the next row. Instead of spaces, print now uses a dash to glue the three pieces.
Worked example
print("2024", "07", "15", sep="-")sep replaces the space between each pair of items
Why: Instead of spaces, print now uses a dash to glue the three pieces.
Read the output
Why: Verified by execution.
| setting | output |
|---|---|
| default (space) | 2024 07 15 |
| sep="-" | 2024-07-15 |
| sep="" | 20240715 |
Concept
Normally print finishes with a new line. end="..." replaces that ending with whatever you choose.
end="..." with no new line keeps the next print on the same line - useful for building one line from several prints.
Sorting
Sort into buckets
These are the pieces of Session 1 - Getting Started: Code, Output & Syntax, out of order. Put each one back under the part of the lesson it belongs to.
Step zero
Discussion prompt
Keeping output on one line with end — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.
Hint: It starts with: Line 1 ends with ... instead of a new line
Answer:
Worked example
print("Loading", end="...")
print("done")Line 1 ends with ... instead of a new line
Why: So the cursor stays on the same line after Loading...
Line 2 continues on that same line
Why: Verified by execution: the two prints share one line.
Read the output
Why: One line, not two.
| line | ends with | screen |
|---|---|---|
| 1 | ... | Loading... |
| 2 | new line | Loading...done |
Intuition
Think of one print as: item sep item sep item ... end.
sep is the glue between the pieces you passed. end is what gets tacked on after the last one. Change either without touching the pieces themselves.
Ranking
Put in order
Put the moves of sep and end together into the order they have to happen.
Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. Verified by execution: prints Hithere!
Worked example
print("Hi", "there", sep="", end="!\n")sep="" removes the space between Hi and there
Why: The two items glue directly: Hithere.
end="!\n" finishes with ! then a new line
Why: Verified by execution: prints Hithere! on its own line.
Read the output
Why: Both defaults overridden at once.
| part | value | effect |
|---|---|---|
| sep | "" | no gap between items |
| end | "!\n" | ! then new line |
| output | Hithere! | on one line |
Section
Part 4
Concept
Any text in quotes is a string. "Hello", 'yes', and "123" are all strings.
string (str) — A sequence of characters wrapped in quotes. The quotes are not part of the text - they just mark where it starts and ends.
Definition probe
Sort into buckets
Every line below is part of the definition of statement or of string (str) — one or the other, never both. Put each where it belongs.
Explain it to yourself
Discussion prompt
In Single or double quotes this move is made:
Both kinds make a string
Why is that legal? Name the rule or definition it rests on before you read on.
Hint: If you can only say "because that is what you do", the rule is the thing to go and find.
Answer:
Python does not care which you use, as long as the opening and closing quotes match.
Worked example
print('Single quotes work')
print("Double quotes work too")Both kinds make a string
Why: Python does not care which you use, as long as the opening and closing quotes match.
Read the output
Why: Verified by execution - the quotes themselves never appear on screen.
| you write | shows |
|---|---|
| 'Single quotes work' | Single quotes work |
| "Double quotes work too" | Double quotes work too |
Concept
Need a quote character inside the text? Use the other kind for the outside.
Apostrophe inside? Wrap in double quotes: "I'm here". Double quote inside? Wrap in single: 'She said "hi"'.
Explain it to yourself
Discussion prompt
In Mixing the two quote styles this move is made:
Outer quotes differ from the inner character
Why is that legal? Name the rule or definition it rests on before you read on.
Hint: If you can only say "because that is what you do", the rule is the thing to go and find.
Answer:
Double outside lets an apostrophe live inside; single outside lets double quotes live inside.
Worked example
print("I'm learning Python")
print('She said "hi"')Outer quotes differ from the inner character
Why: Double outside lets an apostrophe live inside; single outside lets double quotes live inside.
Read the output
Why: Verified by execution.
| you write | shows |
|---|---|
| "I'm learning Python" | I'm learning Python |
| 'She said "hi"' | She said "hi" |
Comparison
Comparison matrix
From Mixing the two quote styles: refill the shows column from what you know. The rest of the table is as it appeared.
| you write | shows |
|---|---|
| "I'm learning Python" | I'm learning Python |
| 'She said "hi"' | She said "hi" |
Anomaly
Predict first
A student writes this, and it looks reasonable:
An apostrophe inside single quotes ends the string early.
It is wrong. Say what breaks — and say it before you turn the page.
Correct: Python reads 'I' as the whole string, then trips on the leftover m here' - a SyntaxError.
Use double quotes on the outside so the apostrophe is safe.
Why: Python reads 'I' as the whole string, then trips on the leftover m here' - a SyntaxError.
Trap
An apostrophe inside single quotes ends the string early.
print('I'm here')The apostrophe closes the string too soon
Why: Python reads 'I' as the whole string, then trips on the leftover m here' - a SyntaxError.
| you write | result |
|---|---|
| print('I'm here') | SyntaxError: unterminated string literal |
Use double quotes on the outside so the apostrophe is safe.
print("I'm here")Different outer quotes keep the apostrophe inside
Why: The string runs from the first " to the last ", so the ' is just a character. Real output: I'm here.
| you write | shows |
|---|---|
| print("I'm here") | I'm here |
Concept
A backslash starts an escape code - a stand-in for a character you cannot type plainly.
\n is a new line; \t is a tab (a jump to the next alignment stop). They are each one character, even though you type two.
escape sequence — A backslash followed by a letter that stands for a special character. \n means newline, \t means tab.
Worked example
print("Line 1\nLine 2")The \n inside the string breaks it into two lines
Why: Even though it is one print, the \n forces a new line in the middle.
Read the output
Why: Verified by execution.
| screen line | shows |
|---|---|
| 1 | Line 1 |
| 2 | Line 2 |
Worked example
print("Name\tScore")
print("Sam\t100")\t jumps to the next tab stop
Why: It pads to a column so the second pieces line up under each other.
Read the output
Why: Verified by execution - Score and 100 align in a column.
| you write | shows (aligned) |
|---|---|
| "Name\tScore" | Name Score |
| "Sam\t100" | Sam 100 |
Concept
Between two strings, + glues them together end to end. This is called concatenation.
It adds no spaces - you include them yourself: "Hello" + " " + "World".
Worked example
print("Hello" + " " + "World")+ joins the strings in order
Why: "Hello" then a space string then "World" - glued into one string before printing.
Read the output
Why: Verified by execution. Note the space is its own " " piece.
| expression | builds | shows |
|---|---|---|
| "Hello" + " " | "Hello " | - |
| + "World" | "Hello World" | Hello World |
Concept
A string * a number repeats it: "=" * 10 is ten equals signs. Great for quick separator lines.
Worked example
print("=" * 10)
print("ab" * 3)* repeats the whole string that many times
Why: "=" ten times; "ab" three times glued together.
Read the output
Why: Verified by execution.
| expression | shows |
|---|---|
| "=" * 10 | ========== |
| "ab" * 3 | ababab |
Anomaly
Predict first
A student writes this, and it looks reasonable:
Trying to glue a number onto text with +.
It is wrong. Say what breaks — and say it before you turn the page.
Correct: + cannot join a str and an int - Python refuses to guess whether you meant text or math, and stops.
Use a comma instead - print handles the mix for you.
Why: + cannot join a str and an int - Python refuses to guess whether you meant text or math, and stops.
Trap
Trying to glue a number onto text with +.
print("Age: " + 5)One side is text, the other a number
Why: + cannot join a str and an int - Python refuses to guess whether you meant text or math, and stops.
| expression | result |
|---|---|
| "Age: " + 5 | TypeError: can only concatenate str (not "int") to str |
Use a comma instead - print handles the mix for you.
print("Age:", 5)Commas let print show text and numbers together
Why: print converts the number to text and adds a space. Real output: Age: 5. (Converting with str(5) also works - more on that next session.)
| expression | shows |
|---|---|
| print("Age:", 5) | Age: 5 |
Break the constraint
Discussion prompt
The rule this trap just fixed:
Use a comma instead - print handles the mix for you.
Now break it on purpose. Build a case that violates it and follow the consequences until something visibly fails. Where does the failure first show up — and would you have noticed it if you had not been looking?
Hint: The dangerous rules are the ones whose violation still produces an answer. If yours fails loudly, try to find one that fails quietly.
Answer:
+ cannot join a str and an int - Python refuses to guess whether you meant text or math, and stops.
Concept
If you write an arithmetic expression with numbers, Python computes it first, then prints the result.
print(2 + 3) shows 5. But print("2 + 3") shows the text 2 + 3 - quotes turn off the math.
Step zero
Discussion prompt
Math vs text in print — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.
Hint: It starts with: Line 1: bare numbers get added first
Answer:
Worked example
print(2 + 3)
print("2 + 3 =", 2 + 3)Line 1: bare numbers get added first
Why: 2 + 3 is computed to 5, then 5 is printed.
Line 2: the quoted part stays text, the bare part is computed
Why: Verified by execution: the label "2 + 3 =" is shown as-is, and the real sum 5 follows it.
Read the output
Why: Quotes decide: math or literal text.
| you write | shows |
|---|---|
| print(2 + 3) | 5 |
| print("2 + 3 =", 2 + 3) | 2 + 3 = 5 |
Section
Part 5
Concept
Anything after a # on a line is a comment - Python ignores it completely. It is a note for humans.
comment — Text after a # that Python skips. Use it to explain what a line does or why, without changing the program.
Matching
Match the pairs
Match each term to the definition this lesson gave it — not the one you would guess from the word.
Why: These are the working definitions of statement, string (str), escape sequence, comment as Session 1 - Getting Started: Code, Output & Syntax uses them. Pairing them correctly is the test of whether you could state each one with the slide switched off.
Ranking
Put in order
Put the moves of Comments are invisible to Python into the order they have to happen.
Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. Line 3 has real code, but the # in front means Python never runs it.
Worked example
# greet the user
print("Hello!") # this runs
# print("Goodbye!")Line 1 and line 3 are pure comments - skipped
Why: Line 3 has real code, but the # in front means Python never runs it.
Line 2 runs; the note after # is ignored
Why: Verified by execution: only Hello! is printed. Goodbye! never appears - it is commented out.
Read the output
Why: One line of output from three lines of file.
| line | runs? | output |
|---|---|---|
| 1 | no (comment) | - |
| 2 | yes | Hello! |
| 3 | no (comment) | - |
Error analysis
Annotate
Walk the callouts on Comments are invisible to Python. Each one is a place this is easy to get subtly wrong.
Concept
The best comments do not repeat what the code obviously does - they explain the reason or a tricky detail.
# add tax is more useful than # multiply by 1.08. Write for the person (often future you) reading it later.
Intuition
Your file has two readers: Python, which runs the code, and humans, who need to understand it.
Code is for Python; comments are for humans. # is the switch that says 'this part is only for the people'.
Section
Part 6
Concept
Everyone's code errors constantly. An error is not failure - it is Python telling you where and why it got stuck.
The last line of an error names the problem type. Learning to read that line is a real skill, and we start with the two most common.
Explain it
Discussion prompt
Explain Errors are normal - read them to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.
Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.
Answer:
Everyone's code errors constantly. An error is not failure - it is Python telling you where and why it got stuck.
Anomaly
Predict first
A student writes this, and it looks reasonable:
You want to print the word Hello, but leave off the quotes.
It is wrong. Say what breaks — and say it before you turn the page.
Correct: Bare words are treated as variable names.
Wrap the text in quotes so Python treats it as words.
Why: Bare words are treated as variable names. Nothing was ever named Hello, so it stops.
Trap
You want to print the word Hello, but leave off the quotes.
print(Hello)Without quotes, Python thinks Hello is a name to look up
Why: Bare words are treated as variable names. Nothing was ever named Hello, so it stops.
| you write | result |
|---|---|
| print(Hello) | NameError: name 'Hello' is not defined |
Wrap the text in quotes so Python treats it as words.
print("Hello")Quotes turn it into text to display
Why: Now Python shows the characters between the quotes. Real output: Hello.
| you write | shows |
|---|---|
| print("Hello") | Hello |
Concept
NameError: name 'X' is not defined means you used a bare word X that Python does not recognize - no variable, no quotes.
Two usual fixes: you meant text (add quotes), or you meant a variable you forgot to create or mistyped.
Analogy
Discussion prompt
Explain What a NameError means by analogy to something with no Python Fundamentals in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.
Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.
Answer:
NameError: name 'X' is not defined means you used a bare word X that Python does not recognize - no variable, no quotes.
Anomaly
Predict first
A student writes this, and it looks reasonable:
Writing print like a sentence, without the parentheses.
It is wrong. Say what breaks — and say it before you turn the page.
Correct: Without them the line is not a valid statement, so Python refuses to run the file at all.
Hand the text to print inside parentheses.
Why: Without them the line is not a valid statement, so Python refuses to run the file at all.
Trap
Writing print like a sentence, without the parentheses.
print "hi"Python 3 requires the parentheses on print
Why: Without them the line is not a valid statement, so Python refuses to run the file at all.
| you write | result |
|---|---|
| print "hi" | SyntaxError: Missing parentheses in call to 'print'. |
Hand the text to print inside parentheses.
print("hi")The parentheses are how you call the function
Why: print( ... ) means 'run print on this'. Real output: hi.
| you write | shows |
|---|---|
| print("hi") | hi |
Two truths and a lie
Sort into buckets
Some of these hold up and some are the exact mistakes this lesson is built to prevent. Sort them.
Concept
A SyntaxError means the line is not written in a form Python can understand, so it will not even start running.
Usual culprits: a missing parenthesis, a missing quote, or a missing colon. Python points an arrow near where it got confused.
Counterexample
Discussion prompt
A SyntaxError means the line is not written in a form Python can understand, so it will not even start running.
That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.
Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.
Answer:
Usual culprits: a missing parenthesis, a missing quote, or a missing colon. Python points an arrow near where it got confused.
Explain it to yourself
Discussion prompt
In An unclosed parenthesis this move is made:
The fix: add the closing )
Why is that legal? Name the rule or definition it rests on before you read on.
Hint: If you can only say "because that is what you do", the rule is the thing to go and find.
Answer:
Verified by execution: print("hi") then shows hi. Matching brackets is the number-one syntax habit to build.
Worked example
print("hi"Every ( needs a matching )
Why: The opening parenthesis is never closed, so Python reaches the end of the line still waiting for a ).
| you write | result |
|---|---|
| print("hi" | SyntaxError: '(' was never closed |
The fix: add the closing )
Why: Verified by execution: print("hi") then shows hi. Matching brackets is the number-one syntax habit to build.
Blank canvas
Draw it
Draw what An unclosed parenthesis just did — the shape of it, not the line-by-line working. One picture, labels only where you need them. Then check it against the steps: anything you could not draw is a step you followed rather than understood.
Explain it to yourself
Discussion prompt
In Writing any line of output this move is made:
4. Close every bracket and quote, then run and read
Why is that legal? Name the rule or definition it rests on before you read on.
Hint: If you can only say "because that is what you do", the rule is the thing to go and find.
Answer:
Match each ( with ) and each opening quote with a closing one. Then run top to bottom and check the screen.
Pattern
1. Pick the tool: print, then open a parenthesis
Why: print( ... ). Forgetting the parentheses is a SyntaxError.
2. Put text in quotes, numbers bare, values comma-separated
Why: "Score:", 100. Forgetting quotes around a word is a NameError; commas let print mix types.
3. Shape it if needed: sep, end, \n, \t
Why: Change the glue between items or how the line finishes, without touching the items themselves.
4. Close every bracket and quote, then run and read
Why: Match each ( with ) and each opening quote with a closing one. Then run top to bottom and check the screen.
Real world
Discussion prompt
Outside this lesson: where does Session 1 - Getting Started: Code, Output & Syntax actually turn up? Name one concrete situation — a job, a piece of software someone ships, a decision somebody has to make — and say which part of Writing any line of output is doing the work in it.
Hint: Vague is the failure mode here. "Engineering" is not a situation; "deciding whether this build is fast enough to ship" is.
Answer:
Session 1 of the universal Python Fundamentals series, in depth. What a program is and how Python runs it top to bottom; print() in full - multiple values, sep and end, blank lines; strings with single and double quotes, quotes-inside-quotes, and the escape codes \n and \t; joining with + and repeating with *; comments; and the two errors every beginner hits (missing quotes -> NameError, missing parentheses -> SyntaxError).
Section
Part 7
Check
Trace it top to bottom.
print("A")
print("B")| line | shows |
|---|---|
| 1 | ? |
| 2 | ? |
Check your understanding
What does this display?
Answer: A
Why: Each print() ends its own line, so the two calls show A then B on separate lines. Verified by execution.
Trade off
Comparison matrix
From Check: two separate prints: every row here is a choice with a cost. Fill the shows column, then say which row you would actually pick and what you give up for it.
| line | shows |
|---|---|
| 1 | ? |
| 2 | ? |
Check
Remember what sep replaces.
print("a", "b", "c", sep="*")| expression | output |
|---|---|
| print(...) | ? |
Check your understanding
What does this print?
Answer: A
Why: sep is the separator placed between each pair of items, so the three letters are joined by . Verified by execution: ab*c.
Check
How many lines land on screen?
print("one\ntwo\nthree")| \n count | lines |
|---|---|
| 2 | ? |
Check your understanding
How many lines does this print?
Answer: A
Why: Each \n starts a new line. Two \n split the text into three lines: one, two, three. Verified by execution.
Check
String times a number.
print("ha" * 3)| expression | output |
|---|---|
| "ha" * 3 | ? |
Check your understanding
What does this print?
Answer: A
Why: A string times a whole number repeats it that many times, glued together with no spaces: hahaha. Verified by execution.
Check
Look carefully at the word in the parentheses.
print(Welcome)| you write | result |
|---|---|
| print(Welcome) | ? |
Check your understanding
What happens when this runs?
Answer: B
Why: Welcome has no quotes, so Python treats it as a variable name and looks it up. Nothing was named Welcome, so it stops with a NameError. Adding quotes fixes it. Verified by execution.
Check
Watch what end does to the first line.
print("3", end="-")
print("2", end="-")
print("1")| line | ends with |
|---|---|
| 1 | - |
| 2 | - |
| 3 | new line |
Check your understanding
What does this print?
Answer: A
Why: The first two prints end with a dash instead of a new line, so all three stay on one line joined by dashes; the last print ends the line normally. Verified by execution: 3-2-1.
Comparison
Comparison matrix
From Check: end on the same line: refill the ends with column from what you know. The rest of the table is as it appeared.
| line | ends with |
|---|---|
| 1 | - |
| 2 | - |
| 3 | new line |
Connect it up
Draw it
One page, no notation unless you need it: draw how these connect — How Python Runs Your Code · print(): Showing Output · Controlling How It Looks · Strings & Escape Codes · Comments & Readable Code · The Two Beginner Errors. Put an arrow wherever one of them is what makes another possible, and label the arrow with why.
Recap
A program runs top to bottom. print() shows text (in quotes) and numbers (bare); commas mix them with spaces.
sep, end, blank print(), \n, and \t.+, repeat with *; + needs both sides to be text.# writes a comment for humans - Python ignores it.| Symptom | Likely cause |
|---|---|
| NameError: ... not defined | missing quotes around text |
| SyntaxError: Missing parentheses | wrote print without ( ) |
| SyntaxError: '(' was never closed | forgot a closing ) |
| TypeError: can only concatenate | used + on text and a number |
Python is a literal reader - quotes, parentheses, and spelling all matter. Next session we start storing values in variables so the program can remember things.
Want this taught 1-on-1? Alexander tutors Python Fundamentals — $55/session, free consultation.