- Matplotlib for Python Developers
- Aldrin Yim Claire Chung Allen Yu
- 163字
- 2021-08-27 18:48:19
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.
推薦閱讀
- Visual Basic .NET程序設(shè)計(jì)(第3版)
- 精通JavaScript+jQuery:100%動(dòng)態(tài)網(wǎng)頁(yè)設(shè)計(jì)密碼
- 騰訊iOS測(cè)試實(shí)踐
- TradeStation交易應(yīng)用實(shí)踐:量化方法構(gòu)建贏家策略(原書(shū)第2版)
- JavaScript入門(mén)經(jīng)典
- Swift語(yǔ)言實(shí)戰(zhàn)精講
- Illustrator CC平面設(shè)計(jì)實(shí)戰(zhàn)從入門(mén)到精通(視頻自學(xué)全彩版)
- Java7程序設(shè)計(jì)入門(mén)經(jīng)典
- ABAQUS6.14中文版有限元分析與實(shí)例詳解
- SSH框架企業(yè)級(jí)應(yīng)用實(shí)戰(zhàn)
- 深入淺出 HTTPS:從原理到實(shí)戰(zhàn)
- WCF全面解析
- Java EE基礎(chǔ)實(shí)用教程
- 絕密原型檔案:看看專(zhuān)業(yè)產(chǎn)品經(jīng)理的原型是什么樣
- iOS應(yīng)用逆向工程:分析與實(shí)戰(zhàn)