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

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.

主站蜘蛛池模板: 林周县| 宿松县| 灵石县| 黑水县| 诸城市| 伽师县| 枣阳市| 新和县| 宝应县| 镇安县| 巴彦淖尔市| 读书| 淮滨县| 山丹县| 平谷区| 莫力| 吴旗县| 丰台区| 民乐县| 正宁县| 赫章县| 黄大仙区| 土默特左旗| 大港区| 海兴县| 石柱| 万荣县| 乌鲁木齐县| 金平| 贵阳市| 丰顺县| 集贤县| 苗栗市| 商水县| 阿克| 巩义市| 昌平区| 崇阳县| 荣成市| 额尔古纳市| 察雅县|