python——python数组相关操作

索引从0开始

输出数组中的值

list1 = ['a', 'b', 'c']
print(list1[0])
# a
print(list1[1:3])
# ['b', 'c']  输出索引从1到3之间的数

修改数组中的值

list1 = ['a', 'b', 'c']
list1[0] = '123'
print(list1)
# ['123', 'b', 'c']

添加数组中的值: append

list1 = ['a', 'b', 'c']
list1.append('d')
print(list1)
# ['a', 'b', 'c', 'd']

Guess you like

Origin blog.csdn.net/qq_43201350/article/details/120110042