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

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.

主站蜘蛛池模板: 长岭县| 朔州市| 义马市| 观塘区| 霍州市| 河池市| 比如县| 平塘县| 镶黄旗| 天柱县| 辰溪县| 睢宁县| 自治县| 盐城市| 蒲江县| 晋城| 安宁市| 石景山区| 淮阳县| 尉犁县| 启东市| 金川县| 铁岭市| 敦化市| 湟中县| 交口县| 保德县| 池州市| 三亚市| 仁寿县| 太康县| 乐平市| 高雄市| 读书| 溧阳市| 天长市| 辰溪县| 新昌县| 图木舒克市| 屏山县| 常熟市|