打印功能反斜杠消失了Python 3

时间:2015-08-26 23:11:01

标签: python printing

游戏中的反斜杠消失了,我怎样才能让它们可见?

__author__ = 'daniel'
# Game Over 2.0
# demonstrates the use of quotes in strings

print ("Program 'Game Over' 2.0")

print ("Same","message","as before")

print ("Just",
       "a bit",
       "bigger")

print ("Here", end=" ")
print ("it is.....")

print(
        """
         _____       ___       ___  ___   _____
        /  ___|     /   |     /   |/   | |  ___|
        | |        / /| |    / /|   /| | | |__
        | |  _    / ___ |   / / |__/ | | |  __|
        | |_| |  / /  | |  / /       | | | |___
        \_____/ /_/   |_| /_/        |_| |_____|

         _____   _     _   _____   _____
        /  _  \ | |   / / |  ___| |  _  \
        | | | | | |  / /  | |__   | |_| |
        | | | | | | / /   |  __|  |  _  /
        | |_| | | |/ /    | |___  | | \ \
        \_____/ |___/     |_____| |_|  \_\

        """
     )

input("\n\nPress the enter key to exit.")

1 个答案:

答案 0 :(得分:2)

'\'字符被视为转义字符。使用r前缀将其视为原始字符串文字

print(
       r"""
         _____       ___       ___  ___   _____
        /  ___|     /   |     /   |/   | |  ___|
        | |        / /| |    / /|   /| | | |__
        | |  _    / ___ |   / / |__/ | | |  __|
        | |_| |  / /  | |  / /       | | | |___
        \_____/ /_/   |_| /_/        |_| |_____|

         _____   _     _   _____   _____
        /  _  \ | |   / / |  ___| |  _  \
        | | | | | |  / /  | |__   | |_| |
        | | | | | | / /   |  __|  |  _  /
        | |_| | | |/ /    | |___  | | \ \
        \_____/ |___/     |_____| |_|  \_\

        """
     )