3.Python自學之路:list的操作執行個體

來源:互聯網
上載者:User

標籤:操作   nbsp   執行個體   code   style   logs   span   存在   字元   

 1 l1 = list([‘w‘,‘u‘,‘w‘,‘e‘,‘n‘]) 2 l1.append(‘i‘) 3 l1.append([‘s‘,‘s‘])  #將參數以原類型追加 4 l1.append(‘sb‘) 5 l1.append(6)    #可以添加數字 6 print(l1) 7  8 result = l1.count(‘s‘) 9 print(result)10 11 #extend只能添加iterable進去當參數:數組,字串,列表12 l1.extend([‘66‘,‘77‘]) #將參數的內容拓展進去13 l1.extend(‘88‘)    #字串被拆開了14 l1.extend(‘999‘)   #不能添加數字進去,報錯15 print(l1)16 17 result = l1.index(‘w‘)  #尋找,返回下標18 print(result)19 20 l1.insert(5,‘lol‘)21 print(l1)22 23 result = l1.pop(5)  #彈出第5個元素,儲存在result中24 print(result)25 26 l1.remove(‘66‘)   #不存在該元素就報錯27 print(l1)28 29 l1.reverse()   #倒置30 print(l1)31 32 l1 = list((‘5‘,‘6‘,‘2‘,‘3‘,‘7‘)) #排序33 l1.sort()34 print(l1)

 

3.Python自學之路:list的操作執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.