简体   繁体   中英

How can I make the following text appear in my python program?

I want to display the following text in my program.When ever I paste the following text in python it interprets backslash as escape sequence and mess ups my ascii art..any idea to get this solved geeks.Here is the text I want to appear in my program

  _  __     _ _           _         ____            _               _                 
 | |/ /__ _| | | __ _  __| | __ _  |  _ \ __ _  ___| | ____ _  __ _(_)_ __   __ _ ___ 
 | ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
 | . \ (_| | | | (_| | (_| | (_| | |  __/ (_| | (__|   < (_| | (_| | | | | | (_| \__ \
 |_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_|   \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
                                                              |___/         |___/     

You can use raw strings:

myString = r'''_  __     _ _           _         ____            _               _                 
 | |/ /__ _| | | __ _  __| | __ _  |  _ \ __ _  ___| | ____ _  __ _(_)_ __   __ _ ___ 
 | ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
 | . \ (_| | | | (_| | (_| | (_| | |  __/ (_| | (__|   < (_| | (_| | | | | | (_| \__ \
 |_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_|   \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
                                                          |___/         |___/'''
# note the r before the string starts

More Info

Try testing the difference between print '\\tHello, world!' and print r'\\tHello, World!'

use triple quotes, place this text between """ """

>>> strs="""_  __     _ _           _         ____            _               _                 
 | |/ /__ _| | | __ _  __| | __ _  |  _ \ __ _  ___| | ____ _  __ _(_)_ __   __ _ ___ 
 | ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
 | . \ (_| | | | (_| | (_| | (_| | |  __/ (_| | (__|   < (_| | (_| | | | | | (_| \__ \
 |_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_|   \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
                                                              |___/         |___/     """
>>> print(strs)
_  __     _ _           _         ____            _               _                 
 | |/ /__ _| | | __ _  __| | __ _  |  _ \ __ _  ___| | ____ _  __ _(_)_ __   __ _ ___ 
 | ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
 | . \ (_| | | | (_| | (_| | (_| | |  __/ (_| | (__|   < (_| | (_| | | | | | (_| \__  |_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_|   \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
                                                              |___/         |___/   
ascii_art = r"""_  __     _ _           _         ____            _               _                 
 | |/ /__ _| | | __ _  __| | __ _  |  _ \ __ _  ___| | ____ _  __ _(_)_ __   __ _ ___ 
 | ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
 | . \ (_| | | | (_| | (_| | (_| | |  __/ (_| | (__|   < (_| | (_| | | | | | (_| \__ \
 |_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_|   \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
                                                              |___/         |___/     """
print ascii_art

Use r"""text""" to avoid backslashes escaping EOL's.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM