common operations:
len(s) length of s min(s) smallest item of s max(s) largest item of s x in s 1 if an item of s is equal to x, else 0 x not in s 0 if an item of s is equal to x, else 1 s + t the concatenation of s and t s * n, n * s n copies of s concatenated s[i] i'th item of s, origin 0 s[i:j] slice of s from i to j slice from index i up to but not including index j i defaults to 0, j to len(s) negative goes from right-end of sequence
slice from index i up to but not including index j
i defaults to 0, j to len(s)
negative goes from right-end of sequence
List is like array in other language
Tutples are like list, but they are immutable.
s[i] = x item i of s is replaced by x s[i:j] = t slice of s from i to j is replaced by t del s[i:j] delete slice (same as s[i:j] = []) s.append(x) add x to end of s s.count(x) return number of i's for which s[i] == x s.index(x) return smallest i such that s[i] == x1) s.insert(i, x) item i becomes x, old item i is now at i+1, etc. s.remove(x) same as del s[s.index(x)] s.reverse() reverses the items of s (in place) s.sort() sorts the list (in place) Optional parameter: function of two arguments returning -1, 0 or 1 depending on whether arg1 is >, ==, < arg2.
example:
L = [ 'abc', 123, 1.23]
len(L) //3
L.append(3)
L
['abc', 123, 1.23, 3]