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

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":

主站蜘蛛池模板: 文昌市| 嘉黎县| 增城市| 长岭县| 上高县| 吴江市| 雅安市| 巫山县| 新密市| 榆树市| 焦作市| 邹城市| 乐业县| 阳西县| 玉田县| 堆龙德庆县| 黄大仙区| 龙门县| 肥西县| 民乐县| 霍林郭勒市| 海淀区| 特克斯县| 建始县| 钟山县| 华宁县| 旬邑县| 巨野县| 敦化市| 白玉县| 丰县| 文山县| 日照市| 弥渡县| 兰西县| 平乡县| 浪卡子县| 蒙城县| 华安县| 墨江| 阳江市|