1.列表的索引,获取与修改
如何在列表中通过使用索引和切片来修改列表?
1)list[index] = new_item
2)数据的修改只能在存在的索引范围内。...例1:
tests = ['a','b','c']
tests[2]='s'
print(tests)
运行结果: ['a', 'b', 's']
3)列表无法通过添加新的索引的方式来赋值。...list assignment index out of range
进程已结束,退出代码为 1
4)list.index(item)
这个index函数,通过传入一个元素,从而查找到这个元素对应的索引值...:',numbers[:])
print('另一种获取完整列表的方法:',numbers[0:])
print('第三种获取列表的方法:',numbers[0:-1])
print('列表的反序:',numbers...: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
另一种获取完整列表的方法: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
第三种获取列表的方法: [1, 2, 3,