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

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

主站蜘蛛池模板: 阳曲县| 吉木萨尔县| 安平县| 金坛市| 通城县| 灵川县| 金沙县| 基隆市| 关岭| 铜山县| 花垣县| 灵宝市| 无为县| 仙游县| 玛多县| 班戈县| 玛多县| 孝感市| 唐河县| 扎兰屯市| 临城县| 炎陵县| 五原县| 远安县| 青田县| 牟定县| 清水河县| 昭平县| 北京市| 类乌齐县| 安乡县| 关岭| 南昌市| 阆中市| 广河县| 浮山县| 孝昌县| 册亨县| 奇台县| 于田县| 海淀区|