使用List操作符
def myList = ['a', 'b', 'c', 'd', 'e', 'f'] //getAt(ranges) assert myList[0..2] == ['a', 'b', 'c'] //getAt(collection of index) assert myList[1, 3, 5] == ['b', 'd', 'f'] //putAt(ranges) myList[0..2] = ['x', 'y', 'z'] assert myList == ['x', 'y', 'z', 'd', 'e', 'f' ] //removing elements myList[0..2] = [] assert myList == ['d', 'e', 'f' ] //adding elements myList[1..1] = ['x', 'y'] assert myList == ['d', 'x', 'y', 'e', 'f']
本文详细介绍了如何使用Python中的List操作符进行元素获取、插入、删除和添加,包括范围指定的元素获取、多个元素获取、元素替换、元素移除及新增元素等常见操作。
1869

被折叠的 条评论
为什么被折叠?



