-1

Is there a way to litterally print an escape sequence such as \n? For example:

print "Hello\nGoodbye" 

The output of this would be:

Hello Goodbye 

Is there a way to get it to literally print out this?

Hello\nGoodbye 
0

3 Answers 3

4

You can use raw strings (see here). Just add an r before the string:

>>> print r"hello\nworld" hello\nworld 
Sign up to request clarification or add additional context in comments.

Comments

3

You can place the string in repr:

>>> mystr = "Hello\nGoodbye" >>> print mystr Hello Goodbye >>> print repr(mystr) 'Hello\nGoodbye' >>> # Remove apostrophes >>> print repr(mystr)[1:-1] Hello\nGoodbye >>> 

Comments

1

Simpy write:

r'Hello\nGoodbye' 

r is for raw string.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.