hello everyone , I have observed something strange The lines print('$!/\\@$@!') and print('$!/\@$@!') are yielding same result . Can someone say why can this happen. | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

hello everyone , I have observed something strange The lines print('$!/\\@$@!') and print('$!/\@$@!') are yielding same result . Can someone say why can this happen.

21st Oct 2016, 7:54 PM
Sivasai Vemuri
Sivasai Vemuri - avatar
3 Antworten
+ 1
You just discovered that the backlash (\) character escapes some characters, that otherwise have a special meaning. For more information read this please: https://learnpythonthehardway.org/book/ex10.html
21st Oct 2016, 8:26 PM
Amarie
+ 1
Because backslash hints Python to expect a 'special escape sequence'. When one is not found (@ is not special), it dumps both \ and @. Compare: >>> print('\\\\') \\ >>> print('\\\\ \@') \\ \@ >>> print('\\\\ \n') \\ <----- \n is "newline" (empty line here) >>> Learn Python The Hard Way (Escape Sequences section): https://learnpythonthehardway.org/book/ex10.html
22nd Oct 2016, 12:09 PM
Kirk Schafer
Kirk Schafer - avatar
0
if that is the case, the output of the first statement must be $!/\@$@! and that of second must be $!/@$@!, right?
22nd Oct 2016, 3:20 AM
Sivasai Vemuri
Sivasai Vemuri - avatar