Python 如何打印没有空格的文本行
我试图从用户那里获取两个值,并使用用户输入打印一行文本Python 如何打印没有空格的文本行,python,Python,我试图从用户那里获取两个值,并使用用户输入打印一行文本 char1 = input("Please enter the first character: ") char2 = input("Please enter the secound character: ") width = int(input("Please enter the width of the innermost triangle: ")) if width % 2 == 0: print ("ERROR - nu
char1 = input("Please enter the first character: ")
char2 = input("Please enter the secound character: ")
width = int(input("Please enter the width of the innermost triangle: "))
if width % 2 == 0:
print ("ERROR - number is even")
quit()
print ("")
print (char1*11,char2*1,char1*11)
这是我当前的输出:
YYYYYYYYYYY + YYYYYYYYYYY
我正在尝试打印它,没有空格,因此它看起来像这样:
YYYYYYYYYYY+YYYYYYYYYYY
如何执行此操作?按如下方式打印输出:
print ("{}{}{}".format(char1*11,char2*1,char1*11))
如果您使用的是Python 3,也可以使用sep:
print (char1*11,char2*1,char1*11, sep="")
请在此处阅读有关打印的更多信息:
可能存在的副本