Python中常用列表方法分享

來源:互聯網
上載者:User
本文主要和大家分享Python中常用列表方法,主要以代碼的形式和大家講解,希望能協助到大家。

append(...) 在列表尾部添加元素
| L.append(object) -> None -- append object to end

count(...) 檢查列表元素中是否存在該內容

| L.count(value) -> integer -- return number of occurrences of value

extend(...) 合并列表

| L.extend(iterable) -> None -- extend list by appending elements from the iterable

insert(...) 在某個元素前插入元素

| L.insert(index, object) -- insert object before index

pop(...) 刪除某個元素 預設是最後一個 pop(0)就是刪除第一個元素
| L.pop([index]) -> item -- remove and return item at index (default last).

| Raises IndexError if list is empty or index is out of range.

sort(...) 排序 要求元素類型一致,否則會出錯!

| L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE*

reverse(...) 逆序

| L.reverse() -- reverse *IN PLACE*

| remove(...) 刪除某個值的元素
| L.remove(value) -> None -- remove first occurrence of value.
| Raises ValueError if the value is not present.

聯繫我們

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