How do I include an ASCII art string literal without getting syntax errors in Python?

720 Views Asked by At

Whenever I put an ASCII art in Python code it gives an error from the characters the ASCII art contains. What do I do?

Here is my code:

print('            ____...------------...____
               _.-"` /o/__ ____ __ __  __ \o\_`"-._
             .'     / /                    \ \     '.
             |=====/o/======================\o\=====|
             |____/_/________..____..________\_\____|
             /   _/ \_     <_o#\__/#o_>     _/ \_   \
             \_________\####/_________/
              |===\!/========================\!/===|
              |   |=|          .---.         |=|   |
              |===|o|=========/     \========|o|===|
              |   | |         \() ()/        | |   |
              |===|o|======{'-.) A (.-'}=====|o|===|
              | __/ \__     '-.\uuu/.-'    __/ \__ |
              |==== .'.'^'.'.====|
          jgs |  _\o/   __  {.' __  '.} _   _\o/  _|
              `=====================================')
2

There are 2 best solutions below

2
jsbueno On

You have to paste any ASCII art in a triple-quote raw-string, like this:

art = r"""
<paste ascii art here>

"""
0
Robert On

You can also use print() with triplet of double or single quotes:

print("""*here is
my favorite
ASCII art*""")

or

print('''*here is
my favorite
ASCII art*''')