how to display a cat in python

There are multiple ways to display a cat in Python, one of the easiest and the most common ways is to use ASCII art. Here is an example of a cat:

main.py
  /\_/\
 ( o   o )
  =\   /=
   )\_/(    |\_/|
  /|\ /|\  / @ @ \
  \_/ \_/ ( >y< )
             "" ""
103 chars
8 lines

You can print it to the console using the print() function as follows:

main.py
print("  /\\_/\\")
print(" ( o   o )")
print("  =\\   /=")
print("   )\\_/(")
print("  /|\\ /|\\    |\\_/|")
print("  \\_/ \\_/    / @ @ \\")
print("             ( >y< )")
print("            '' ''")
199 chars
9 lines

This will output the cat to the console:

main.py
  /\_/\
 ( o   o )
  =\   /=
   )\_/(    |\_/|
  /|\ /|\  / @ @ \
  \_/ \_/ ( >y< )
             "" ""
103 chars
8 lines

Note that you need to use backslashes to escape the characters that have a special meaning in Python, such as \ and ".

Alternatively, you can store the cat as a string variable and then print it:

main.py
cat = """
  /\_/\\
 ( o   o )
  =\   /=
   )\_/(    |\\_/|
  /|\\ /|\\  / @ @ \\
  \\_/ \\_/ ( >y< )
             "" ""
"""

print(cat)
136 chars
12 lines

This will also output the cat to the console.

related categories

gistlibby LogSnag