Input & output | SoloLearn: Learn to code for FREE!

+2

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.

7/6/2019 10:24:55 AM

KHADIJA AI

6 Answers

New Answer

+2

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.

+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?

+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.

+3

I understand now. Thanks for explaining it to me.

+1

No worries 😊

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