python--列表list()操作

來源:互聯網
上載者:User
關於列表list的操作
 ·a = list() //建立一個新的列表
 ·a.append('b') //往數組a裡添加新的元素,但一次只能添加一個
 ·a.extend(['hello','world'])或者a.extend(c)//其中c是一個列表  extend作用是為數組拓展多個元素或者一個列表
 ·a.count('hello') //意思即為計算資料行表a裡hello出現的次數
 ·a.index('world') //意思是查詢world這個元素並返回world在列表裡的下標
 ·a.pop()  //刪除列表a最後一個元素
 ·a.pop('2') //刪除a列表中第三個元素
 ·a.remove('hello') //刪除a列表中第一次出現的hello
 ·a.insert(2,'haha') //往列表a中第二個元素之後添加一個元素
 ·a.reverse() //將列表a中的元素翻轉過來
 ·a.sort() //按ASCII碼值升序排序
 ·a.sort(reverse=True) //降序排序
 ·

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.