定義:[]內(nèi)以逗號分隔,按照索引,存放各種數(shù)據(jù)類型,每個位置代表一個元素
網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè),成都做網(wǎng)站公司-創(chuàng)新互聯(lián)建站已向近千家企業(yè)提供了,網(wǎng)站設(shè)計,網(wǎng)站制作,網(wǎng)絡(luò)營銷等服務(wù)!設(shè)計與技術(shù)結(jié)合,多年網(wǎng)站推廣經(jīng)驗,合理的價格為您打造企業(yè)品質(zhì)網(wǎng)站。
列表的創(chuàng)建
list_test=[‘張三‘,‘李四’,'alex'] #或 list_test=list('alex') #或 list_test=list([‘張三‘,‘李四’,'alex'])
特性:
1.可存放多個值
2.按照從左到右的順序定義列表元素,下標從0開始順序訪問,有序
3.可修改指定索引位置對應(yīng)的值,可變
#索引 >>> l = ['egon','alex','seven','yuan'] >>> l[0] 'egon' >>> l[2] 'seven' #切片 >>> l[0:2] ['egon', 'alex'] >>> l[2:5] ['seven', 'yuan'] >>> l[:2] ['egon', 'alex'] >>> l[2:] ['seven', 'yuan'] >>> l[:] ['egon', 'alex', 'seven', 'yuan'] >>> l[::2] ['egon', 'seven'] >>> l[::-1] ['yuan', 'seven', 'alex', 'egon'] #追加 >>> l.append("eva") >>> l ['egon', 'alex', 'seven', 'yuan', 'eva'] #刪除 >>> l.remove('eva') >>> l ['egon', 'alex', 'seven', 'yuan'] >>> l.pop() 'yuan' >>> l ['egon', 'alex', 'seven'] #長度 >>> len(l) 3 #包含 >>> 'seven' in l True >>> 'yuan' in l False #循環(huán):為什么是“i”? >>> for i in l: print(i) egon alex seven
#分割 >>> s = 'hello world' >>> s.split(' ') ['hello', 'world'] >>> s2= 'hello,world' >>> s2.split(',') #連接 >>> l = ['hi','eva'] >>> '!'.join(l) 'hi!eva'
>>> range(1,100) range(1, 100) >>> list(range(1,100)) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99] >>> list(range(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list(range(0,100,2)) [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98]
網(wǎng)頁標題:python數(shù)據(jù)類型之列表
文章源于:http://jinyejixie.com/article10/pgehgo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、網(wǎng)站設(shè)計公司、服務(wù)器托管、建站公司、App設(shè)計、
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)