是否可以創建一個變量來存儲產品列表,而不是使用「行」變量。當創建一個文本文件在Python中創建文本文件
#creating a textfile
text_file= open("productlist.txt", "w")
lines = ("Bed","\n","Couch","\n","Mirror","\n","Television","\n"
"Tables","\n","Radio")
text_file.writelines(lines)
text_file.close()
text_file = open("productlist.txt")
print(text_file.read())
text_file.close()
你的意思是'lines = text_file.readlines()'也許? –
@ Jean-FrançoisFabre不,我想知道是否可以在創建此列表時使用其他變量 lines =(「Bed」,「\ n」,「Couch」,「\ n」,「Mirror」, 「\ n」,「電視」,「\ n」「表格」,「\ n」,「收音機」) – Charisma
我真的不知道你的意思。您可以根據需要創建儘可能多的變量。 –