Unit 11.1A · Term 1

Output & Escape Sequences

Every program needs to communicate with the user. In Python, print() is the main tool for displaying information. This lesson focuses on organising output with sep and end, and using escape sequences to control formatting.

Learning Objectives

  • 11.1.1.1 Organize data output
  • 11.1.1.2 Use the escape sequences with data output

Lesson Presentation

11.1A-lesson-01-output.pdf · Slides for classroom use

Video Explanation

Watch a visual walkthrough of Python output and formatting.

Conceptual Anchor

The Billboard Analogy

Think of print() as a digital billboard. You choose what to display, how items are separated using sep, and what comes after the output using end. Escape sequences are formatting controls that create new lines, tabs or special characters.

Anatomy of print()

Values"A", "B", "C"

The objects that Python displays.

Separatorsep="-"

Text inserted between multiple values. Default: one space.

Endend="!"

Text added after all values. Default: newline \n.

# General form print(value1, value2, ..., sep=' ', end='\n') print("Hello, World!") print("Name:", "Ali") print("2026", "09", "30", sep="-") print("Loading", end="...") print("Done!") print() # blank line

Output Predictor

Predict the exact output before revealing it. Pay attention to spaces, line breaks, sep and end.


                            
Predict first, then reveal the output.

Print Playground

Change the values, separator and ending. The preview models one print() statement.

Generated statement
Preview
                                    

                                

Escape Sequences

An escape sequence begins with a backslash and represents a special character inside a string.

Escape Sequence Meaning Example Output
\n New line Line 1, then Line 2 on the next line
\t Horizontal tab / next tab stop Useful for tabbed spacing
\\ Backslash character C:\Users\
\' Single quote It's
\" Double quote He said "Hi"

Escape Sequence Explorer

Code

                                    
Output

                                

About \t

\t inserts a horizontal tab and advances to the next tab stop. Its visible width depends on the terminal, editor or environment, so do not treat it as “exactly eight spaces”.

Code vs Output

Study how tiny changes affect output. The last examples show common errors.

1. Default separator
Code
print("A", "B", "C")
Output
A B C
2. Empty separator
Code
print("A", "B", "C", sep="")
Output
ABC
3. New lines inside one string
Code
print("A\nB\nC")
Output
A
B
C
4. Newline as separator
Code
print("A", "B", "C", sep="\n")
Output
A
B
C
5. Two print() calls joined
Code
print("Loading", end="...")
print("Done")
Output
Loading...Done
6. sep + end together
Code
print("A", "B", sep=":", end=" | ")
print("C")
Output
A:B | C
7. Tabbed spacing
Code
print("Name\tScore")
print("Ali\t95")
Output
Name    Score
Ali     95
8. Blank line
Code
print("Top")
print()
print("Bottom")
Output
Top

Bottom
9. Error — missing comma
Code
print("Score:" 95)
Result
SyntaxError
10. Error — broken quotes
Code
print('It's raining')
Result
SyntaxError
11. Unexpected path output
Code
print("C:\new\test")
Output
C:
ew	est
12. Error — str + int
Code
age = 16
print("Age: " + age)
Result
TypeError

File Paths: Escaped vs Raw Strings

Windows-style paths can accidentally contain \n and \t. Two common solutions are shown below.


                        

Extension

Raw strings are useful when text contains many backslashes, but the core objective remains understanding escape sequences.

Worked Examples


                                

                            

Fix the Output

Find the most important problem, then choose the best correction.


                            

Pitfalls & Common Errors

Forgetting Escape in File Paths

print("C:\new\test") interprets \n as a newline and \t as a tab. Use "C:\\new\\test" or, where appropriate, r"C:\new\test".

Mixing Quote Types Incorrectly

print('It's raining') causes a syntax error. Use print("It's raining") or print('It\'s raining').

Missing Comma Between Arguments

print("Score:" 95) is invalid. Use print("Score:", 95).

Concatenating Text and Numbers Directly

"Age: " + 16 causes a TypeError. Use print("Age:", 16) or convert the number with str().

Forgetting What end Does

end="" or end=" " means the next print() begins on the same line.

Pro-Tips for Exams

Output Questions

  • Write the output exactly, including spaces, punctuation and line breaks.
  • Default sep=' ' is one space.
  • Default end='\n' moves to the next line.
  • print() with no values outputs only its ending, so the default creates a blank line.
  • \t moves to a tab stop; do not assume exactly eight spaces.
  • With several print() calls, trace where the previous end leaves the cursor.

Graded Tasks

Remember

Match \n, \t, \\, \', \" with their meanings.

Understand

State the exact output of print("A", "B", "C", sep="-").

Apply

Use sep to print 2026-09-30 from three separate values.

Apply

Use end so the numbers 1 to 5 are printed on the same line.

Apply

Print the path C:\Users\student\Documents\homework.py correctly.

Analyze

Write the exact output of print("A", "B", sep=":", end=" | "); print("C\nD").

Create

Create a formatted receipt using print(), \t, \n, sep and end. Include at least three items, prices and a total.

Exam Practice

Q1: Write the exact output. [2]
print("Red", "Green", "Blue", sep="/")

Reveal marking point
Red/Green/Blue

Q2: Write the exact output. [3]
print("A", "B", sep=":", end=" | ")
print("C\nD")

Reveal marking points
A:B | C D

Q3: Explain why print("C:\new\test") does not display the intended path. [2]

Reveal marking points
Backslash begins escape sequences. \n becomes a newline and \t becomes a tab instead of literal path characters.

Q4: Correct print('It's ready'). [1]

Reveal marking point
For example: print("It's ready") or print('It\'s ready').

Self-Check Quiz

1. What is the default value of sep?
A single space: ' '.
2. What does \t do?
It inserts a horizontal tab and advances to the next tab stop.
3. What is the output of print("A", "B", "C", sep="-", end="!")?
A-B-C!
4. How do you place a literal backslash inside a normal Python string?
Use \\.
5. What happens with print("Hello\nWorld")?
Hello is printed on one line and World on the next.