Operation | Result | Trans |
---|---|---|
x in s |
True if an item of s is equal to x, else False
|
x值是否在s列表中 |
x not in s |
False if an item of s is equal to x, else True
|
x值是否不在s列表中 |
s + t |
the concatenation of s and t | 拼接s和t |
s * n or n * s
|
equivalent to adding s to itself n times | 将s列表重复n遍 |
s[i] |
ith item of s, origin 0 | 取s列表中某一个值 |
s[i:j] |
slice of s from i to j | 切片方式取s列表中 i 到(j-1)的连续索引对应的值 |
s[i:j:k] |
slice of s from i to j with step k | 切片方式取s列表中 i 到(j-1),步长为k的索引对应的值 |
len(s) |
length of s | 获取s列表的长度 等同于 s.__len__() |
min(s) |
smallest item of s | 获取s列表中的最小值 |
max(s) |
largest item of s | 获取s列表中的最大值 |
s.index(x[, i[, j]]) |
index of the first occurrence of x in s (at or after index i and before index j) | 获取x值在s列表中(从索引 i 到(j-1))的索引(第一个出现的) |
s.count(x) |
total number of occurrences of x in s | 获取x值在s列表中的个数 |
Operation | Result | Trans |
---|---|---|
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 the contents of the iterable t | |
del s[i:j] |
same as s[i:j] = []
|
|
s[i:j:k] = t |
the elements of s[i:j:k] are replaced by those of t
|
|
del s[i:j:k] |
removes the elements of s[i:j:k] from the list |
|
s.append(x) |
appends x to the end of the sequence (same as s[len(s):len(s)] = [x] ) |
|
s.clear() |
removes all items from s (same as dels[:] ) |
|
s.copy() |
creates a shallow copy of s (same as s[:] ) |
|
s.extend(t) or s += t
|
extends s with the contents of t (for the most part the same as s[len(s):len(s)]= t ) |
|
s *= n |
updates s with its contents repeated n times | |
s.insert(i, x) |
inserts x into s at the index given by i(same as s[i:i] = [x] ) |
|
s.pop([i]) |
retrieves the item at i and also removes it from s | |
s.remove(x) |
remove the first item from s where s[i]== x
|
|
s.reverse() |
reverses the items of s in place |