python中list方法詳解說明
阿新 • • 發佈:2018-12-02
序號 | 分類 | 關鍵字/函式/方法 | 描述 |
1 | 新增 | list.insert(索引,資料) | 在指定位置插入資料 |
list.append(資料) | 在list末尾追加資料 | ||
list.extend(list2) | 將list2的資料追加到list | ||
2 | 修改 | list[索引] = 資料 | 修改指定索引的資料 |
3 | 刪除 | del list[索引] | 刪除指定索引的資料 |
list.remove[資料] | 刪除第一個出現的指定資料 | ||
list.pop | 刪除末尾的資料 | ||
list.pop(索引) | 刪除指定索引的資料 | ||
list.clear | 清空列表 | ||
4 | 統計 | len(list) |
統計列表長度 |
list.count(資料) | 統計指定資料在列表中出現的次數 | ||
5 | 排序 | list.sort() | 按升序排列 |
list.sort(reverse=True) | 按降序排列 | ||
list.reverse() | 逆序、反轉 |
使用示例: