Prev: More String Operations Up: Sequence Types Top: Top
s[i] = x
s[i:j] = t
del s[i:j]
s[i:j] = []
s.append(x)
s[len(s):len(s)] = [x]
s.count(x)
s[i] == x
s.index(x)
s[i] == x
--- (1)
s.insert(i, x)
s[i:i] = [x]
s.remove(x)
del s[s.index(x)]
--- (1)
s.reverse()
s.sort()
s[i] <= s[j]
,
for i < j
--- (2)
sort()
method takes an optional argument
specifying a comparison function of two arguments (list items) which
should return -1
, 0
or 1
depending on whether the
first argument is considered smaller than, equal to, or larger than the
second argument. Note that this slows the sorting process down
considerably; e.g. to sort an array in reverse order it is much faster
to use calls to sort()
and reverse()
than to use
sort()
with a comparison function that reverses the ordering of
the elements.