0
0
Pythonprogramming~15 mins

Escape characters in output in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Escape characters in output
📖 Scenario: Imagine you are writing a message that includes special characters like quotes and new lines. You want to show this message exactly as it is, including the special characters, in your program's output.
🎯 Goal: You will create a string with escape characters and print it so the output shows the special characters correctly.
📋 What You'll Learn
Create a string variable with escape characters for quotes and new lines
Use the correct escape sequences like \" for double quotes and \n for new lines
Print the string so the output matches the expected format
💡 Why This Matters
🌍 Real World
Escape characters are used when you want to include special symbols or formatting inside text, like quotes, new lines, or tabs, which is common in writing messages, logs, or formatted output.
💼 Career
Understanding escape characters helps in programming tasks like generating reports, handling file paths, or preparing text for display or storage, which are common in many software development jobs.
Progress0 / 4 steps
1
Create a string with quotes and new lines
Create a string variable called message with the exact value: She said, \"Hello!\"\nWelcome to the escape characters lesson.
Python
Need a hint?

Use \" to include double quotes inside the string and \n for a new line.

2
Add a second line with a tab escape character
Add to the message string a new line with a tab character and the text: \tThis line is indented. Use the plus sign + to join the strings.
Python
Need a hint?

Use \n for new line and \t for tab inside the string you add.

3
Print the message variable
Write a print statement to display the message variable exactly as it is.
Python
Need a hint?

Use print(message) to show the string with escape characters interpreted.

4
Print the raw string with escape characters visible
Print the message variable so that the output shows the escape characters like \n and \t as text, not as new lines or tabs. Use the repr() function inside the print statement.
Python
Need a hint?

Use print(repr(message)) to show the string with escape characters visible.