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

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.
主站蜘蛛池模板: 特克斯县| 尚义县| 清涧县| 石泉县| 会东县| 大名县| 石林| 卢湾区| 桂东县| 义乌市| 当阳市| 沾益县| 武威市| 靖西县| 江北区| 黄平县| 堆龙德庆县| 青浦区| 三穗县| 汝南县| 浪卡子县| 双桥区| 巴楚县| 瑞安市| 东山县| 枣阳市| 蒙自县| 安西县| 同江市| 邓州市| 河池市| 甘洛县| 平果县| 兴山县| 闸北区| 民权县| 泌阳县| 尼玛县| 普宁市| 云南省| 津市市|