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

Complex data structures

You can also have complex data structures with lists. So you don't have to just put numbers in it; you can actually put strings in it. You can put numbers in it. You can put other lists in it. It doesn't matter. Python is a weakly-typed language, so you can pretty much put whatever kind of data you want, wherever you want, and it will generally be an OK thing to do:

y = [10, 11, 12]
listOfLists = [x, y]
listOfLists

In the preceding example, I have a second list that contains 10, 11, 12, that I'm calling y. I'll create a new list that contains two lists. How's that for mind blowing? Our listofLists list will contain the x list and the y list, and that's a perfectly valid thing to do. You can see here that we have a bracket indicating the listofLists list, and within that, we have another set of brackets indicating each individual list that is in that list:

[[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [10, 11, 12]]

So, sometimes things like these will come in handy.

主站蜘蛛池模板: 卫辉市| 沙湾县| 沙河市| 西乌| 河源市| 上杭县| 安国市| 麟游县| 孝昌县| 玉田县| 陕西省| 梅河口市| 玉溪市| 页游| 龙游县| 绥宁县| 乌兰浩特市| 泸定县| 宣威市| 沧源| 怀安县| 英超| 安泽县| 沧源| 武定县| 波密县| 青铜峡市| 同仁县| 徐汇区| 庄河市| 五家渠市| 迭部县| 临高县| 西峡县| 静乐县| 泸西县| 云霄县| 石林| 正安县| 当涂县| 隆德县|