我試圖將包含2個浮點數和3個文本部分的元組轉換爲一個字符串,所以我可以在file.write()中使用它,因爲它不是接受元組。將浮點數和文本組成的元組轉換爲單個字符串
testr = 'you went' ,speed ,'mph and stopped in' ,stop ,'meters'
test = open('testresults.txt' ,'w')
test.write(testr)
test.close()
每當我嘗試運行它給了我這個
test.write(testr)
TypeError: must be str, not tuple
謝謝它的工作!有沒有可能你可以解釋這是如何工作的?所以我可以用其他方式或其他項目來工作。 –