官术网_书友最值得收藏!

Merging and updating lists

List merging can be done in two ways in Python. First, we can use the traditional + operator, which we used previously to concatenate two strings. It does the same when used on list object types. The other way to achieve this would be by using the extend method, which takes the new list as an argument to be merged with the existing list. This is shown in the following example:

To update an element in the list, we can access its index and add the updated value for any element that we wish to update. For example, if we want to have the string Hello as the 0th element of the list, this can be achieved by assigning the 0th element to the Hello value as merged[0]="hello":

主站蜘蛛池模板: 社会| 滨州市| 长沙市| 图片| 黄山市| 龙江县| 茌平县| 光泽县| 长垣县| 丽水市| 二连浩特市| 商河县| 漳浦县| 南涧| 祥云县| 临邑县| 兴海县| 常州市| 安远县| 会理县| 库伦旗| 丰镇市| 宝鸡市| 扬州市| 阳谷县| 阳泉市| 宝丰县| 霍山县| 阳高县| 山阴县| 普兰县| 调兵山市| 巴彦淖尔市| 阳曲县| 贺州市| 调兵山市| 扎囊县| 旌德县| 汾阳市| 岑巩县| 馆陶县|