String Escaping with Special Characters #
The backslash also \ tells Python that the following character should be interpreted as a special character instead of a regular character. For example, if you want to include a newline character in a string (from pressing Enter), you can use the escape sequence \n. Or if you want to include a tab character (from pressing Tab), you can use the escape sequence \t.
For example, we can print multiple lines of text with the special character \n, like so:
print("Hello\nworld!")
# Hello
# world!
And because the backslash is a special character, to use a baskslash in a string also requires escaping as well:
print("C:\\Users\\John\\Documents")
# Output: C:\Users\John\Documents
Exercise #
- Fix the value of
file_pathto beC:\Users\John\Documents
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules