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

Adding list to list

You can also change lists around. Let's say I want to add a list to the list. I can use the extend function for that, as shown in the following code block:

x.extend([7,8])
x

The output of the above code is as follows:

[1, 2, 3, 4, 5, 6, 7, 8]

I have my list of 1, 2, 3, 4, 5, 6. If I want to extend it, I can say I have a new list here, [7, 8], and that bracket indicates this is a new list of itself. This could be a list implicit, you know, that's inline there, it could be referred to by another variable. You can see that once I do that, the new list I get actually has that list of 7, 8 appended on to the end of it. So I have a new list by extending that list with another list.

主站蜘蛛池模板: 台湾省| 三门县| 唐海县| 铜梁县| 肃宁县| 永顺县| 郁南县| 云阳县| 寻乌县| 荔浦县| 定襄县| 开江县| 阜康市| 抚顺市| 江达县| 南汇区| 赣榆县| 子长县| 古浪县| 萨嘎县| 鄢陵县| 枝江市| 从化市| 万荣县| 台南县| 山东| 赤水市| 阿拉善左旗| 额尔古纳市| 武宣县| 西乌珠穆沁旗| 新兴县| 福贡县| 吉林市| 泗水县| 波密县| 建德市| 耒阳市| 买车| 舟山市| 淮滨县|