Input & output | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Input & output

I don't understand why there is a double Backslash in here: 'This is what\\nthe user enters!'. As I learned from the last lesson, '/n' is automatically put in the output where Enter was pressed. Thanks for giving an answer.

6th Jul 2019, 10:24 AM
KHADIJA AI
KHADIJA AI - avatar
7 Answers
+ 3
Yeah, this is quite tricky. The string is saved containing a double backslash so that, when it is printed, it returns exactly what the user entered. The backslash is an escape character which means the next character has a special purpose. The backslash and the character after it are not printed normally. Escaping the backslash (i.e. a double backslash) means that it does get printed (along with everything else). See here: https://code.sololearn.com/cJF11138P0ZA/?ref=app Hope this helps.
6th Jul 2019, 12:52 PM
Russ
Russ - avatar
+ 4
This means that a slash has been added to the phrase to escape from the( \n) 's mission, which is escaping a new line, and that to only print what actually the user had entered. It isn't?
6th Jul 2019, 1:16 PM
KHADIJA AI
KHADIJA AI - avatar
+ 4
Yeah, I think what you're saying is right. The backslash is the escape character. It tells the parser to deal with the following charcter differently. If you escape the escape charcter, you are telling the parser to leave the escape charcter as it is, and to print it as normal. This means that the newline gets ignored.
6th Jul 2019, 1:45 PM
Russ
Russ - avatar
+ 3
I understand now. Thanks for explaining it to me.
6th Jul 2019, 1:57 PM
KHADIJA AI
KHADIJA AI - avatar
+ 1
No worries 😊
6th Jul 2019, 1:58 PM
Russ
Russ - avatar
0
double backslash means \ or \n means new line :) like This : print("Hey\nHello") #output Hey Hello print("GNU\\LInux") #output GNU\Linux print("Don\"t") #output: don"t print("don't") # output don't print("Hello\tWorld") #output Hello World
30th Jul 2020, 4:47 AM
Mohammad Qureshi
Mohammad Qureshi - avatar
0
Hi
9th Dec 2021, 1:18 PM
KAPILI DIPAK