序列类型
6种:列表、元组、字符串、Unicode字符串、buffer对象、xrange对象
列表(list)
操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| "a" + "b"
"ab" * 2 [None] * 10
"p" in "python"
numbers = [1, 5, 3] len(numbers) max(numbers) min(numbers)
list("Hello")
numbers[1] = 20
del numbers[0]
data[start:end:interval]
numbers = [1, 2, 3, 4, 5] numbers[1: 4] = []
numbers.append(2)
numbers.count(1)
numbers.extend([3, 4, 5])
numbers.index(3) numbers.pop(0) numbers.reverse() numbers.sort()
|
元组
不可修改
1 2 3
| a = (1, 2, 3) a = (1, ) a = tuple([1, 2, 3])
|