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
list(s)— returns a list of the sequences.s.append(x)— appends elementxto the end ofs.s.extend(x)— appends the listxtos.s.count(x)— counts the occurrences ofxins.s.index(x, [start], [stop])— returns the smallest indexiwheres[i] == x. Optionalstart/stopnarrow the search.s.insert(i, e)— insertsxat indexi.s.pop(i)— returns the element at indexiand removes it from the list.s.remove(x)— removesxfroms.s.reverse()— reverses the order ofs.s.sort(key, [reverse])— sortss, with an optionalkeyandreverse.
List Operations
- Indexing —
[ ]— access an element of a sequence. - Concatenation —
+— combine sequences together. - Repetition —
*— concatenate a sequence a repeated number of times. - Membership —
in— ask whether an item is in a sequence. - Length —
len— ask the number of items in the sequence. - Slicing —
[ : ]— extract part of a sequence.