Editor settings

General settings

Save settings

Learn to program with Python

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_path to be C:\Users\John\Documents
Output will be displayed here