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

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

主站蜘蛛池模板: 深州市| 合江县| 资兴市| 咸阳市| 阿荣旗| 偃师市| 雷州市| 易门县| 安阳市| 友谊县| 锦州市| 伊宁市| 北川| 子洲县| 澎湖县| 吉隆县| 乐都县| 随州市| 卓尼县| 南漳县| 盖州市| 资源县| 鹤岗市| 根河市| 临洮县| 宿迁市| 武山县| 高青县| 嘉峪关市| 洪泽县| 西乡县| 工布江达县| 桑植县| 中方县| 施秉县| 玛纳斯县| 吉林省| 乡宁县| 宝坻区| 苗栗市| 平泉县|