我正在学习如何创建列表并将两个列表添加在一起-这是我尝试的
my_list = ('one' , 'two' , 'three')
another_list =('four' , 'five')
new_list = (my_list + another_list)
print(new_list)
然而,当运行它时,我得到一个异常
TypeError: can only concatenate tuple (not "list") to tuple
对于列表,您需要使用方括号-[]
而不是大括号-()
。尝试——
my_list = ['one', 'two', 'three']
another_list = ['four', 'five']
new_list = my_list + another_list
print(new_list)