我需要从数组中的多个位置提取数据。
一个简单的数组是:-
listing = (4, 22, 24, 34, 46, 56)
我熟悉切片。例如:-
listing[0:3]
会给我:-
(4, 22, 24)
但是我无法取出多个切片。例如:-
listing[0:3, 4:5]
给我
TypeError: tuple indices must be integers not tuples
尽管搜索了两本 Python 书籍和互联网,但我无法确定要使用的语法。
原文由 OldSteve 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以切片两次并加入它们。