如何打印列表?打印出列表
def main():
fileName = input("Please input name of file to read: ")
fileOpen = open(fileName)
lineList = fileOpen.readlines()
print("Hercules' Strategy:", lineList[len(lineList)-3].strip())
print("Initial Hydra heads:",lineList[len(lineList)- 2].strip())
print("Hydra growth period:", lineList[len(lineList)-1].strip())
main()
文本文件:
smallest
8 7 3
10
电流输出:
Hercules' Strategy: smallest
Initial Hydra heads: 8 7 3
Hydra growth period: 10
我想获得的输出是认为:
Hercules' Strategy: smallest
Initial Hydra heads: [8, 7, 3]
Hydra growth period: 10
这不是我想的清单。这只是一个字符串。如果你只是想要支架,为什么不'print'['+ you_string +']'' – gongzhitaao
@ gzhngzhitaao是的。这是我现在的问题。我想打印出列表,而不是字符串。 – user2985771
所以你真的想把字符串解析成一个列表? – gongzhitaao