List Methods
Lists are objects and thus have methods. Table 10, List Methods gives some of the most commonly used list methods.
|
Method |
Description |
|---|---|
|
L.append(v) |
Appends value v to list L |
|
L.clear() |
Removes all items from list L |
|
L.count(v) |
Returns the number of occurrences of v in list L |
|
L.extend(v) |
Appends the items in v to L |
|
L.index(v) |
Returns the index of the first occurrence of v in L—an error is raised if v doesn’t occur in L. |
|
L.index(v, beg) |
Returns the index of the first occurrence of v at or after index beg in L—an error is raised if v doesn’t occur in that part of L. |
|
L.index(v, beg, end) |
Returns the index of the first occurrence of v between indices beg (inclusive) and ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access