Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print "\n" or newline characters as part of the output on terminal

I'm running Python on terminal

Given a string string = "abcd\n"

I'd like to print it somehow so that the newline characters '\n' in abcd\n would be visible rather than go to the next line

Can I do this without having to modify the string and adding a double slash (\\n)

like image 421
wolfgang Avatar asked Jul 25 '15 07:07

wolfgang


1 Answers

Use repr

>>> string = "abcd\n" >>> print(repr(string)) 'abcd\n' 
like image 113
Bhargav Rao Avatar answered Sep 19 '22 13:09

Bhargav Rao