创建一个列表
list1 = ['a', 'b', 'c', 4, 5, 6]
list1.append(8)
list1
['a', 'b', 'c', 4, 5, 6, 8]
list1.insert(1,'f')
list1
['hello world', 'f', 'f', 'f', 'f', 'f', 'b', 'c', 4, 5, 6, 8]
list1[0] = 'hello world'
list1
['hello world', 'f', 'f', 'f', 'f', 'f', 'b', 'c', 4, 5, 6, 8]
列表中删除元素
del list1[-7]
list1
['hello world', 'f', 'f', 'f', 'f', 'b', 'c', 4, 5, 6, 8]
list1.remove('f')
list1
['hello world', 'f', 'b', 'c', 4, 5, 6, 8]
list1.pop(1)
'f'
list1
['hello world', 'b', 'c', 4, 5, 6, 8]
pop_ele = list1.pop(2)
pop_ele
'c'
list1
['hello world', 'b', 4, 5, 6, 8]
列表查找元素
list1[2]
4
list1[0:2]
['hello world', 'b']
list2 = [i for i in range( 10 )]
list2
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list2[0:9:3]
[0, 3, 6]
list2[-9:-1:2]
[1, 3, 5, 7]
print(list2[0:])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print(list2[3::-1])
[3, 2, 1, 0]
len(list2)
10