Reputation: 81
How do I make the backslash so that it becomes visible in the output of the code? I am trying to make a board for a game I am programming. however, the board contains backslashes '\'
print('''
_____________________
/ \
/_______________________\
| | | | |
''')
but what I get is:
>>>
_____________________
/ /_______________________| | | | |
>>>
Upvotes: 2
Views: 167
Reputation: 7136
You need to escape your backslash by preceding it with, yes, another backslash:
print('''
_____________________
/ \\
/_______________________\\
| | | | |
''')
Or instead, you can use r
(or R
) to specify a string literal called "raw strings"-- omitting the need of escaping the backslashes
print(R'''
_____________________
/ \
/_______________________\
| | | | |
''')
Upvotes: 2
Reputation: 2366
In addition to escaping you can use raw print. Notice the r
before the '''
:
print(r'''
_____________________
/ \
/_______________________\
| | | | |
''')
Upvotes: 3