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

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.

主站蜘蛛池模板: 百色市| 宁河县| 江源县| 广东省| 襄垣县| 浮梁县| 华池县| 嘉禾县| 安多县| 霍城县| 湟中县| 盐山县| 澜沧| 房产| 大同县| 台北市| 阿瓦提县| 古交市| 绥江县| 曲阜市| 响水县| 甘谷县| 郑州市| 浦东新区| 三河市| 衡山县| 兰州市| 吕梁市| 朝阳市| 长寿区| 吉隆县| 岫岩| 中西区| 米易县| 烟台市| 闽侯县| 阿拉善左旗| 南漳县| 红原县| 南漳县| 万源市|