Session 1 - Getting Started: Code, Output & Syntax

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

What this lesson covers

The lesson, slide by slide

1. Getting Started: Code, Output & Syntax

Title

Python Fundamentals - Session 1

What a program is, and making the computer talk back with print()

2. What you will be able to do

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:

  1. Explain that Python runs your file top to bottom, one line at a time.
  2. Use print() to display text and numbers - alone, or several at once.
  3. Shape output with sep, end, blank lines, and the escape codes \n and \t.
  1. Join strings with + and repeat them with *.
  2. Write # comments that explain your code.
  3. Read and fix the two errors every beginner hits.

3. How Python Runs Your Code

Section

Part 1

4. A program is a list of instructions

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.

5. Break it if you can: A program is a list of instructions

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.

6. Top to bottom, one line at a time

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.

7. By analogy: Top to bottom, one line at a time

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.

8. Python is a very literal reader

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.

9. Teach it back: Python is a very 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.

10. Writing code vs running it

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.

11. print(): your first instruction

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.

12. print(): Showing Output

Section

Part 2

13. Text goes inside quotes

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.

14. What has to happen first: Your first program

Ranking

Put in order

Put the moves of Your first program into the order they have to happen.

  1. Line 1 runs first and shows the first message
  2. Line 2 runs next, on its own line
  3. Read the output

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.

15. Your first program

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.

linerunsshows on screen
1firstHello, world!
2secondLearning Python.

16. Fill in: runs for Your first program

Comparison

Comparison matrix

From Your first program: refill the runs column from what you know. The rest of the table is as it appeared.

linerunsshows on screen
1firstHello, world!
2secondLearning Python.

17. Numbers need no quotes

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

18. Why is this step legal: Bare numbers print as themselves

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.

19. Printing a number

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 writeshows
print(42)42
print(3.5)3.5

20. What each one costs: Printing a number

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 writeshows
print(42)42
print(3.5)3.5

21. Several values, separated by commas

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.

22. Why is this step legal: Read the output

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.

23. Mixing text and numbers

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 writeshows
print("Score:", 100)Score: 100

24. Draw the shape of it: Mixing text and numbers

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.

25. Predict the next row: More than two values

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

pieceshows as
"x ="x =
55
"and y ="and y =
1010
whole linex = 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.

26. More than two values

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.

pieceshows as
"x ="x =
55
"and y ="and y =
1010
whole linex = 5 and y = 10

27. Each print ends the line

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

28. Two prints, two lines

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.

lineshows
1A
2B

29. An empty print() makes a blank line

Concept

print() with nothing inside prints nothing but a new line - a handy way to add space between blocks of output.

30. Adding a blank line

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.

lineshows
1Top
2(blank)
3Bottom

31. Inspect it line by line: Adding a blank line

Error analysis

Annotate

Walk the callouts on Adding a blank line. Each one is a place this is easy to get subtly wrong.

  • Nothing to show, but it still ends a line - so a gap appears.
  • Verified by execution: Top, a blank line, then Bottom.

32. Controlling How It Looks

Section

Part 3

33. sep: change what goes between

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.

34. Predict the next row: Building a date with sep

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

settingoutput
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.

35. Building a date with sep

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.

settingoutput
default (space)2024 07 15
sep="-"2024-07-15
sep=""20240715

36. end: change how the line finishes

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.

37. Where does each piece belong: Session 1 - Getting Started: Code, Output &…

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.

How Python Runs Your Code
A program is a list of instructions; Top to bottom, one line at a time; Python is a very literal reader
print(): Showing Output
Text goes inside quotes; Your first program; Numbers need no quotes
Controlling How It Looks
sep: change what goes between; Building a date with sep; end: change how the line finishes
s1
How Python Runs Your Code is where Session 1 - Getting Started: Code, Output & Syntax puts A program is a list of instructions, Top to bottom, one line at a time, Python is a very literal reader. Knowing which part of the lesson a problem belongs to is most of knowing which method to reach for.
s2
print(): Showing Output is where Session 1 - Getting Started: Code, Output & Syntax puts Text goes inside quotes, Your first program, Numbers need no quotes. Knowing which part of the lesson a problem belongs to is most of knowing which method to reach for.
s3
Controlling How It Looks is where Session 1 - Getting Started: Code, Output & Syntax puts sep: change what goes between, Building a date with sep, end: change how the line finishes. Knowing which part of the lesson a problem belongs to is most of knowing which method to reach for.

38. Plan first: Keeping output on one line with end

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:

  1. Line 1 ends with ... instead of a new line
  2. Line 2 continues on that same line
  3. Read the output

39. Keeping output on one line with end

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.

lineends withscreen
1...Loading...
2new lineLoading...done

40. sep is glue, end is the finish

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.

41. What has to happen first: sep and end together

Ranking

Put in order

Put the moves of sep and end together into the order they have to happen.

  1. sep="" removes the space between Hi and there
  2. end="!\n" finishes with ! then a new line
  3. Read the output

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!

42. sep and end together

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.

partvalueeffect
sep""no gap between items
end"!\n"! then new line
outputHithere!on one line

43. Strings & Escape Codes

Section

Part 4

44. A string is text in quotes

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.

45. Take the definitions apart: statement vs string (str)

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.

statement
One complete instruction on one line, like print("hi").; A program is a stack of statements run in order.
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.
b1
One complete instruction on one line, like print("hi"). A program is a stack of statements run in order.
b2
A sequence of characters wrapped in quotes. The quotes are not part of the text - they just mark where it starts and ends.

46. Why is this step legal: Both kinds make a string

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.

47. Single or double quotes

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 writeshows
'Single quotes work'Single quotes work
"Double quotes work too"Double quotes work too

48. Quotes inside quotes

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"'.

49. Why is this step legal: Outer quotes differ from the inner character

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.

50. Mixing the two quote styles

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 writeshows
"I'm learning Python"I'm learning Python
'She said "hi"'She said "hi"

51. Fill in: shows for Mixing the two quote styles

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 writeshows
"I'm learning Python"I'm learning Python
'She said "hi"'She said "hi"

52. Something is wrong here: quote clash

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.

53. Trap: quote clash

Trap

The 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 writeresult
print('I'm here')SyntaxError: unterminated string literal

The fix

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 writeshows
print("I'm here")I'm here

54. Escape codes: \n and \t

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.

55. \n makes one string span two lines

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 lineshows
1Line 1
2Line 2

56. \t lines things up

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 writeshows (aligned)
"Name\tScore"Name Score
"Sam\t100"Sam 100

57. Joining strings with +

Concept

Between two strings, + glues them together end to end. This is called concatenation.

It adds no spaces - you include them yourself: "Hello" + " " + "World".

58. Concatenating three pieces

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.

expressionbuildsshows
"Hello" + " ""Hello "-
+ "World""Hello World"Hello World

59. Repeating strings with *

Concept

A string * a number repeats it: "=" * 10 is ten equals signs. Great for quick separator lines.

60. Repeat to draw a line

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.

expressionshows
"=" * 10==========
"ab" * 3ababab

61. Something is wrong here: + needs both sides to be text

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.

62. Trap: + needs both sides to be text

Trap

The 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.

expressionresult
"Age: " + 5TypeError: can only concatenate str (not "int") to str

The fix

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

expressionshows
print("Age:", 5)Age: 5

63. Break it on purpose: + needs both sides to be text

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.

64. Numbers do math, even inside print

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.

65. Plan first: Math vs text in print

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:

  1. Line 1: bare numbers get added first
  2. Line 2: the quoted part stays text, the bare part is computed
  3. Read the output

66. Math vs text in print

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 writeshows
print(2 + 3)5
print("2 + 3 =", 2 + 3)2 + 3 = 5

67. Comments & Readable Code

Section

Part 5

68. # starts a comment

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.

69. Term to definition: Session 1 - Getting Started: Code, Output & Syntax

Matching

Match the pairs

Match each term to the definition this lesson gave it — not the one you would guess from the word.

  • t1. statement
  • t2. string (str)
  • t3. escape sequence
  • t4. comment
  • d1. One complete instruction on one line, like print("hi"). A program is a stack of statements run in order.
  • d2. A sequence of characters wrapped in quotes. The quotes are not part of the text - they just mark where it starts and ends.
  • d3. A backslash followed by a letter that stands for a special character. \n means newline, \t means tab.
  • d4. Text after a # that Python skips. Use it to explain what a line does or why, without changing the program.

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.

70. What has to happen first: Comments are invisible to Python

Ranking

Put in order

Put the moves of Comments are invisible to Python into the order they have to happen.

  1. Line 1 and line 3 are pure comments - skipped
  2. Line 2 runs; the note after # is ignored
  3. Read the output

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.

71. Comments are invisible to Python

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.

lineruns?output
1no (comment)-
2yesHello!
3no (comment)-

72. Inspect it line by line: Comments are invisible to Python

Error analysis

Annotate

Walk the callouts on Comments are invisible to Python. Each one is a place this is easy to get subtly wrong.

  • Line 3 has real code, but the # in front means Python never runs it.
  • Verified by execution: only Hello! is printed. Goodbye! never appears - it is commented out.
  • One line of output from three lines of file.

73. Good comments explain WHY

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.

74. Two audiences, one file

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'.

75. The Two Beginner Errors

Section

Part 6

76. Errors are normal - read them

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.

77. Teach it back: Errors are normal - read them

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.

78. Something is wrong here: forgetting the quotes

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.

79. Trap: forgetting the quotes

Trap

The 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 writeresult
print(Hello)NameError: name 'Hello' is not defined

The fix

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 writeshows
print("Hello")Hello

80. What a NameError means

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.

81. By analogy: What a NameError means

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.

82. Something is wrong here: forgetting the parentheses

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.

83. Trap: forgetting the parentheses

Trap

The 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 writeresult
print "hi"SyntaxError: Missing parentheses in call to 'print'.

The fix

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 writeshows
print("hi")hi

84. Which of these survive contact with Session 1 - Getting Started: Code, Output &…?

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.

Holds up
Writing code is writing a to-do list for the computer. Each line is one instruction.; Python starts at the first line of your file, does it, then moves to the next - down to the bottom, then stops.; Picture Python reading your file with a finger, one line at a time, never guessing what you meant.
Breaks
An apostrophe inside single quotes ends the string early.; Trying to glue a number onto text with +.
sound
These are stated as this lesson states them — each one survives the edge cases Session 1 - Getting Started: Code, Output & Syntax puts it through.
flawed
Each of these is lifted from a trap in this deck: reasonable-sounding, and wrong in a way that only shows up once you rely on it.

85. What a SyntaxError means

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.

86. Break it if you can: What a SyntaxError means

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.

87. Why is this step legal: The fix: add the closing )

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.

88. An unclosed parenthesis

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 writeresult
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.

89. Draw the shape of it: An unclosed parenthesis

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.

90. Why is this step legal: 4. Close every bracket and quote, then run and…

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.

91. Writing any line of output

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.

92. Where this shows up: Session 1 - Getting Started: Code, Output & Syntax

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

93. Check Yourself

Section

Part 7

94. Check: two separate prints

Check

Trace it top to bottom.

print("A")
print("B")
lineshows
1?
2?

Check your understanding

What does this display?

  • A. A and B on two separate lines (correct)
  • B. A B on one line
  • C. AB with no space
  • D. It errors

Answer: A

Why: Each print() ends its own line, so the two calls show A then B on separate lines. Verified by execution.

Why B tempts people
That needs one print with a comma: print("A", "B"). These are two separate calls on two lines.
Why C tempts people
Nothing joins the letters - they are in different print() calls, each ending its line.
Why D tempts people
Both lines are valid: print, parentheses, and quotes are all present.

95. What each one costs: Check: two separate prints

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.

lineshows
1?
2?

96. Check: sep

Check

Remember what sep replaces.

print("a", "b", "c", sep="*")
expressionoutput
print(...)?

Check your understanding

What does this print?

  • A. abc (correct)
  • B. a b c
  • C. abc
  • D. abc

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.

Why B tempts people
That is the default separator (a space). Here sep is set to "*", replacing the spaces.
Why C tempts people
That would need sep="" (empty). Here sep is "*", so a star appears between items.
Why D tempts people
sep goes only BETWEEN items, not before the first or after the last, so there are two stars, not four.

97. Check: counting lines with \n

Check

How many lines land on screen?

print("one\ntwo\nthree")
\n countlines
2?

Check your understanding

How many lines does this print?

  • A. Three (correct)
  • B. One
  • C. Two
  • D. Six

Answer: A

Why: Each \n starts a new line. Two \n split the text into three lines: one, two, three. Verified by execution.

Why B tempts people
It is one print call, but the \n escape codes break the single string into multiple lines.
Why C tempts people
Two \n create three lines, not two - each \n adds a break between pieces.
Why D tempts people
There are only three words and two breaks. Six would need five \n.

98. Check: repeating with *

Check

String times a number.

print("ha" * 3)
expressionoutput
"ha" * 3?

Check your understanding

What does this print?

  • A. hahaha (correct)
  • B. ha ha ha
  • C. ha3
  • D. It errors

Answer: A

Why: A string times a whole number repeats it that many times, glued together with no spaces: hahaha. Verified by execution.

Why B tempts people
* adds no spaces between copies - it joins them directly. Spaces would have to be inside the string.
Why C tempts people
The number is not printed; it is how many times to repeat. The result is three copies of ha.
Why D tempts people
string * int is valid and means repeat. It is str + int that errors, not str * int.

99. Check: spot the error

Check

Look carefully at the word in the parentheses.

print(Welcome)
you writeresult
print(Welcome)?

Check your understanding

What happens when this runs?

  • A. It prints Welcome
  • B. NameError: name 'Welcome' is not defined (correct)
  • C. It prints nothing
  • D. SyntaxError: Missing parentheses

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.

Why A tempts people
It would print Welcome only with quotes. Without them, Python hunts for a variable, not text.
Why C tempts people
It does not run silently - it stops with an error before printing.
Why D tempts people
The parentheses are present, so it is not that error. The missing quotes make it a NameError.

100. Check: end on the same line

Check

Watch what end does to the first line.

print("3", end="-")
print("2", end="-")
print("1")
lineends with
1-
2-
3new line

Check your understanding

What does this print?

  • A. 3-2-1 (correct)
  • B. 3 2 1 on three lines
  • C. 321
  • D. 3-2-1- with a trailing dash

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.

Why B tempts people
end="-" removes the new line on the first two prints, so they do NOT go on separate lines.
Why C tempts people
Each of the first two prints ends with a dash, so dashes appear between the numbers.
Why D tempts people
The last print uses the default end (a new line), not a dash, so there is no trailing dash.

101. Fill in: ends with for Check: end on the same line

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.

lineends with
1-
2-
3new line

102. Connect it up: Session 1 - Getting Started: Code, Output & Syntax

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.

103. What you can do now

Recap

A program runs top to bottom. print() shows text (in quotes) and numbers (bare); commas mix them with spaces.

SymptomLikely cause
NameError: ... not definedmissing quotes around text
SyntaxError: Missing parentheseswrote print without ( )
SyntaxError: '(' was never closedforgot a closing )
TypeError: can only concatenateused + 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.

Sources

  1. Python 3 Tutorial - An Informal Introduction to Python
  2. Python 3 Library Reference - Built-in Functions (print)
  3. Python 3 Reference - String and Bytes literals (escape sequences)
  4. All snippets and error messages executed and copied from CPython 3.12. — Author verification run, 2026-07-15 (Python Fundamentals series, Session 1).

Want this taught 1-on-1? Alexander tutors Python Fundamentals — $55/session, free consultation.

Book on Wyzant · Text (657) 465-8108