orpqK
orpqK

Reputation: 2785

How to print the string "\n"

I want to print the actual following string: \n , but everything I tried just reads it in takes it as a new line operator.. how do I just print the following: \n ?

Upvotes: 1

Views: 1646

Answers (4)

vartec
vartec

Reputation: 134571

You have to escape \n somehow

Either just the sequence

print "\\n"

or mark whole string as raw

print r"\n"

Upvotes: 3

schesis
schesis

Reputation: 59118

You need to escape the backslash:

>>> print("\\n")
\n

Upvotes: 1

Matthias
Matthias

Reputation: 13222

Use

print "\\n"

or a raw string

print r"\n"

Have a look at the tutorial concerning strings.

Upvotes: 13

Achrome
Achrome

Reputation: 7821

Escape the \ with another \.

print "\\n"

Upvotes: 3

Related Questions