0
我正在爲我在學校的一個班級進行任務,我需要將兩個列表連接在一起。我使用的代碼:在python中連接列表時出錯
flowers = ["rose", "bougainvillea", "yukka", "marigold", "daylily", "lily of the valley"]
thorny = flowers[0:3]
poisonous = flowers[-1]
dangerous = flowers[0:3] + flowers[-1]
我不斷收到錯誤消息:
dangerous = list(set(flowers[0:3] + flowers[-1]))
TypeError: can only concatenate list (not "str") to list
我想知道爲什麼這是行不通的。謝謝!
'dangerous = flowers [0:3] + flowers [-1:]' – ozgur