为什么我的三重引号输出有两个换行符?

时间:2019-03-16 01:50:03

标签: python

我试图用发光的眼睛来打印sans undertale(这意味着我必须对变量使用单独的打印行,而不是三重引号),但是输出在包含以下内容的部分的上方和下方有两个空行颜色(与XD一致),我想删除。我认为三引号打印功能满足单行打印功能是有问题的(如非三引号)这是代码:

from termcolor import colored, cprint
text = colored('8XD8', 'cyan')

print ('''

                888888888888888888
            8888                  8888
          88                          88
          88                          88
        88                              88
        88                    888888    88
''')
print ("\t\t88                    ", text,"    88")
print ('''
        88    888888    88    888888    88
          88          888888          88
        8888  88                  88  8888
        88    8888888888888888888888    88
        88      88  88  88  88  88      88
          8888    88888888888888    8888
         88888888888             8888888888
       88  888888888888888888888888888888  88
    8888  88    88      88      88    88  8888
    88      88    888888  888888    88      88
  88    8888  888888    88    888888  8888    88
  88        88    88          88    88        88
  88          88  88          88  88          88
    88      88    8888      8888    88      88
      8888  88    88          88    88  8888
        888888    88888888888888    888888
          8888    88888888888888    8888
        8888888888888888888888888888888888
        8888888888888888  8888888888888888
          888888888888      88888888888
      888888        88      88        888888
      88          8888      8888          88
        8888888888              8888888888
''')

输出看起来像这样:

                888888888888888888
            8888                  8888
          88                          88
          88                          88
        88                              88
        88                    888888    88

        88                     8XD8     88

        88    888888    88    888888    88
          88          888888          88
        8888  88                  88  8888
        88    8888888888888888888888    88
        88      88  88  88  88  88      88
          8888    88888888888888    8888
         88888888888             8888888888
       88  888888888888888888888888888888  88
    8888  88    88      88      88    88  8888
    88      88    888888  888888    88      88
  88    8888  888888    88    888888  8888    88
  88        88    88          88    88        88
  88          88  88          88  88          88
    88      88    8888      8888    88      88
      8888  88    88          88    88  8888
        888888    88888888888888    888888
          8888    88888888888888    8888
        8888888888888888888888888888888888
        8888888888888888  8888888888888888
          888888888888      88888888888
      888888        88      88        888888
      88          8888      8888          88
        8888888888              8888888888

有什么办法可以解决这个问题?

2 个答案:

答案 0 :(得分:0)

假设您正在使用python3,则可以给print一个end参数,默认情况下,print将以换行符结尾,因此您需要用其他类似的东西覆盖它

打印('''

                888888888888888888
            8888                  8888
          88                          88
          88                          88
        88                              88
        88                    888888    88
''', end = "")
print ("\t\t88                    ", "text","    88", end = "")
print ('''
        88    888888    88    888888    88
          88          888888          88
        8888  88                  88  8888
        88    8888888888888888888888    88
        88      88  88  88  88  88      88
          8888    88888888888888    8888
         88888888888             8888888888
       88  888888888888888888888888888888  88
    8888  88    88      88      88    88  8888
    88      88    888888  888888    88      88
  88    8888  888888    88    888888  8888    88
  88        88    88          88    88        88
  88          88  88          88  88          88
    88      88    8888      8888    88      88
      8888  88    88          88    88  8888
        888888    88888888888888    888888
          8888    88888888888888    8888
        8888888888888888888888888888888888
        8888888888888888  8888888888888888
          888888888888      88888888888
      888888        88      88        888888
      88          8888      8888          88
    8888888888              8888888888
''')

答案 1 :(得分:0)

我相信这就是您想要的:

print ('''

                888888888888888888
            8888                  8888
          88                          88
          88                          88
        88                              88
        88                    888888    88''')
print ("        88                    ", text,"    88")
print ('''        88    888888    88    888888    88
          88          888888          88
        8888  88                  88  8888
        88    8888888888888888888888    88
        88      88  88  88  88  88      88
          8888    88888888888888    8888
         88888888888             8888888888
       88  888888888888888888888888888888  88
    8888  88    88      88      88    88  8888
    88      88    888888  888888    88      88
  88    8888  888888    88    888888  8888    88
  88        88    88          88    88        88
  88          88  88          88  88          88
    88      88    8888      8888    88      88
      8888  88    88          88    88  8888
        888888    88888888888888    888888
          8888    88888888888888    8888
        8888888888888888888888888888888888
        8888888888888888  8888888888888888
          888888888888      88888888888
      888888        88      88        888888
      88          8888      8888          88
        8888888888              8888888888
''')

在我的计算机上,我得到了:



                888888888888888888
            8888                  8888
          88                          88
          88                          88
        88                              88
        88                    888888    88
        88                     8XD8     88
        88    888888    88    888888    88
          88          888888          88
        8888  88                  88  8888
        88    8888888888888888888888    88
        88      88  88  88  88  88      88
          8888    88888888888888    8888
         88888888888             8888888888
       88  888888888888888888888888888888  88
    8888  88    88      88      88    88  8888
    88      88    888888  888888    88      88
  88    8888  888888    88    888888  8888    88
  88        88    88          88    88        88
  88          88  88          88  88          88
    88      88    8888      8888    88      88
      8888  88    88          88    88  8888
        888888    88888888888888    888888
          8888    88888888888888    8888
        8888888888888888888888888888888888
        8888888888888888  8888888888888888
          888888888888      88888888888
      888888        88      88        888888
      88          8888      8888          88
        8888888888              8888888888

Python使用您输入的换行符将图形键入为换行符\ n。

让我知道这是否有帮助!