Skip to content
thesarfo

Reference

List Methods & Operations (Python)

Reference for Python's built-in list methods and sequence operations.

views 0

Lists are probably the most used built-in data structure in Python, since they can be composed of any number of other data types — a simple representation of arbitrary objects. Like strings, they are indexed by integers starting at zero.

List Methods

  1. list(s) — returns a list of the sequence s.
  2. s.append(x) — appends element x to the end of s.
  3. s.extend(x) — appends the list x to s.
  4. s.count(x) — counts the occurrences of x in s.
  5. s.index(x, [start], [stop]) — returns the smallest index i where s[i] == x. Optional start/stop narrow the search.
  6. s.insert(i, e) — inserts x at index i.
  7. s.pop(i) — returns the element at index i and removes it from the list.
  8. s.remove(x) — removes x from s.
  9. s.reverse() — reverses the order of s.
  10. s.sort(key, [reverse]) — sorts s, with an optional key and reverse.

List Operations

  1. Indexing[ ] — access an element of a sequence.
  2. Concatenation+ — combine sequences together.
  3. Repetition* — concatenate a sequence a repeated number of times.
  4. Membershipin — ask whether an item is in a sequence.
  5. Lengthlen — ask the number of items in the sequence.
  6. Slicing[ : ] — extract part of a sequence.