list

| Method | Description | Example | | ------------------ | ---------------------------------------------------------------------- | --------------------------- | | `append(x)` | Adds `x` to the end of the list | `list.append(100)` | | `insert(i, x)` | Inserts `x` at position `i` | `list.insert(1, 'hello')` | | `remove(x)` | Removes the **first occurrence** of `x` | `list.remove(4)` | | `pop([i])` | Removes and returns item at position `i` (last if `i` not given) | `list.pop()`, `list.pop(0)` | | `clear()` | Removes **all items** from the list | `list.clear()` | | `index(x)` | Returns the **index** of the first occurrence of `x` | `list.index('dimpul')` | | `count(x)` | Returns the **number of occurrences** of `x` | `list.count(4)` | | `sort()` | Sorts the list **in place** | `list.sort()` | | `reverse()` | Reverses the list **in place** | `list.reverse()` | | `copy()` | Returns a **shallow copy** of the list | `new_list = list.copy()` | | `extend(iterable)` | Extends the list by **appending all elements** from the given iterable | `list.extend([1, 2, 3])` |

Comments

Popular posts from this blog

smart irrigation