如何在python中连接列表?

cre*_*ivz 2 python

我正在尝试将String插入列表中.

我收到了这个错误:

TypeError: can only concatenate list (not "tuple") to list
Run Code Online (Sandbox Code Playgroud)

因为我试过这个:

var1 = 'ThisIsAString' # My string I want to insert in the following list
file_content = open('myfile.txt').readlines()
new_line_insert = file_content[:10] + list(var1) + rss_xml[11:]
open('myfile.txt', 'w').writelines(new_line_insert)
Run Code Online (Sandbox Code Playgroud)

myfile.txt的内容作为列表保存在"file_content"中.我想在第10行之后插入String var1,这就是我做的原因

file_content[:10] + list(var1) + rss_xml[11:]
Run Code Online (Sandbox Code Playgroud)

但列表(var1)不起作用.如何使此代码有效?谢谢!

jbo*_*chi 9

尝试

file_content[:10] + [var1] + rss_xml[11:]
Run Code Online (Sandbox Code Playgroud)