Pius John
PRO
last week
Piuscountry asked

What if i want to print \n as part of the string too

Udayan Shakya
Expert
last week
Udayan Shakya answered

Hello, Pius! If you want to print \n as part of the string, you'll need to write it as \\n like this:

print ("Hey\\nHow are you")

Just like \n is a special code for entering a new line, \\ is special code for entering a single backslash into the string.

So, Python will interpret \\n as:

Print a single backslash '\' followed by the letter 'n'.

Hope that helps! Contact us again if you have further queries.

Python
This question was asked as part of the Learn Python Basics course.