我想在我的程序中显示以下文本。当我在python中粘贴以下文本时,它会将反斜杠解释为转义序列并弄乱我的ascii art ..任何想法让这个解决了geeks.Here是文本我想要出现在我的程序中
_ __ _ _ _ ____ _ _
| |/ /__ _| | | __ _ __| | __ _ | _ \ __ _ ___| | ____ _ __ _(_)_ __ __ _ ___
| ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
| . \ (_| | | | (_| | (_| | (_| | | __/ (_| | (__| < (_| | (_| | | | | | (_| \__ \
|_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_| \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
|___/ |___/
答案 0 :(得分:8)
您可以使用原始字符串:
myString = r'''_ __ _ _ _ ____ _ _
| |/ /__ _| | | __ _ __| | __ _ | _ \ __ _ ___| | ____ _ __ _(_)_ __ __ _ ___
| ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
| . \ (_| | | | (_| | (_| | (_| | | __/ (_| | (__| < (_| | (_| | | | | | (_| \__ \
|_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_| \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
|___/ |___/'''
# note the r before the string starts
尝试测试print '\tHello, world!'
和print r'\tHello, World!'
答案 1 :(得分:3)
使用三重引号,将此文字放在"""
"""
>>> strs="""_ __ _ _ _ ____ _ _
| |/ /__ _| | | __ _ __| | __ _ | _ \ __ _ ___| | ____ _ __ _(_)_ __ __ _ ___
| ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
| . \ (_| | | | (_| | (_| | (_| | | __/ (_| | (__| < (_| | (_| | | | | | (_| \__ \
|_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_| \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
|___/ |___/ """
>>> print(strs)
_ __ _ _ _ ____ _ _
| |/ /__ _| | | __ _ __| | __ _ | _ \ __ _ ___| | ____ _ __ _(_)_ __ __ _ ___
| ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
| . \ (_| | | | (_| | (_| | (_| | | __/ (_| | (__| < (_| | (_| | | | | | (_| \__ |_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_| \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
|___/ |___/
答案 2 :(得分:1)
ascii_art = r"""_ __ _ _ _ ____ _ _
| |/ /__ _| | | __ _ __| | __ _ | _ \ __ _ ___| | ____ _ __ _(_)_ __ __ _ ___
| ' // _` | | |/ _` |/ _` |/ _` | | |_) / _` |/ __| |/ / _` |/ _` | | '_ \ / _` / __|
| . \ (_| | | | (_| | (_| | (_| | | __/ (_| | (__| < (_| | (_| | | | | | (_| \__ \
|_|\_\__,_|_|_|\__,_|\__,_|\__,_| |_| \__,_|\___|_|\_\__,_|\__, |_|_| |_|\__, |___/
|___/ |___/ """
print ascii_art
使用r"""text"""
来避免逃避EOL的反斜杠。