Python3.4打印文本格式()
我将讨论所有这些问题,它们是一些主要的编码问题。在这里,我只是想提示用户输入一个短语,输出结果如下:Python3.4打印文本格式(),python,python-3.x,python-3.4,Python,Python 3.x,Python 3.4,我将讨论所有这些问题,它们是一些主要的编码问题。在这里,我只是想提示用户输入一个短语,输出结果如下: Twas brillig and slithy toves 以下是我到目前为止的情况: stringInput = str.split((input("Enter a phrase: "))) print() for wordPrint in stringInput: print(wordPrint) print() 我可以把它打印出来: Twas bril
Twas
brillig
and
slithy
toves
以下是我到目前为止的情况:
stringInput = str.split((input("Enter a phrase: ")))
print()
for wordPrint in stringInput:
print(wordPrint)
print()
我可以把它打印出来:
Twas
brillig
and
slithy
toves
与:
它只在第二行上加空格,没有其他空格。您需要自己添加空格。下面是一个可能的实现:
for index, word in enumerate(stringInput):
print(' '*index + word)
这奏效了,我已经戳了一段时间了。我是个初学者,谢谢!我需要一个解释来解释它为什么会起作用,所以我自己计算出来:空空格(''=1)乘以枚举单词,1*0=没有空格1*(0,'word1')=0空格,1*(1,'word2')=1空格,1*(2,'word2')=2空格
for index, word in enumerate(stringInput):
print(' '*index + word)