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

List

This is the most basic Python data structure; it stores a collection of values. While you can store any data type as an element in a Python list, for our purpose of data visualization, we mostly handle lists of numerical values as data input, or at, most, lists with elements of the same data type, such as strings to store text labels.

A list is specified by square brackets, []. To initiate an empty list, assign [] to a variable by l = []To create a list, we can write the following:

fibonacci = [1,1,2,3,5,8,13]

Sometimes, we may want to get a list of arithmetic sequences. We may do so by using list(range(start,stop,step)).

See the following example:

In [1]: fifths = list(range(10,30,5))
        fifths
Out[1]: [10, 15, 20, 25]

In [2]: list(range(10,30,5))==[10, 15, 20, 25]
Out[2]: True
Unlike Python 2.7, in Python 3.x, you cannot use the  range()  object interchangeably with a list.
主站蜘蛛池模板: 都江堰市| 桂林市| 鄂温| 固始县| 云阳县| 磴口县| 深泽县| 闸北区| 晋宁县| 广东省| 南乐县| 万山特区| 武定县| 定结县| 隆德县| 秭归县| 鄂托克前旗| 炉霍县| 印江| 浦东新区| 天祝| 屏南县| 锡林郭勒盟| 陈巴尔虎旗| 澳门| 黔西县| 易门县| 云和县| 景东| 新津县| 慈利县| 南和县| 阜康市| 博兴县| 仁寿县| 收藏| 双辽市| 湘潭市| 闻喜县| 宁乡县| 泾源县|