4-10切片:
print("切片")
numbers = ['1', '2', '3', '4', '5', '6', '7', '8']
lenth = len(numbers)
print("the first three items in the list are ")
print(numbers[:3])
print("three items from the middle of the list are ")
print(numbers[2:5])
print("the last three items in the list are ")
print(numbers[-3:])
本文通过实例演示了Python中列表切片的使用方法,包括如何获取列表的前三个元素、中间三个元素以及最后三个元素。这是一篇适合初学者了解Python列表操作技巧的文章。
449

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



