python 运算符 |
Since, function append() is used to insert the elements in the list, that we have disused earlier. There is another way, we can use "+" operator to append the elements in the list.
由于使用了函数append()来将元素插入列表中,因此我们前面已经废弃了。 还有另一种方法,我们可以使用“ +”运算符将元素添加到列表中。
Program:
程序:
# declaring a list with some of the elements
list1 = [10, 20, 30, 40, 50]
# printing the list
print(list1)
# inserting the elements in list
list1 += [60]
list1 += [70, 80]
# print the updated list
print(list1)
Output
输出量
[10, 20, 30, 40, 50]
[10, 20, 30, 40, 50, 60, 70, 80]
翻译自: https://www.includehelp.com/python/extend-a-list-using-plus-operator.aspx
python 运算符 |