51学通信论坛2017新版

标题: 多维列表/元祖访问的示例 [打印本页]

作者: admin    时间: 2019-6-21 23:54
标题: 多维列表/元祖访问的示例
  1. >>> tuple1 = [(2,3),(4,5)]
  2. >>> tuple1[0]
  3. (2, 3)
  4. >>> tuple1[0][0]
  5. 2
  6. >>> tuple1[0][2]
  7. Traceback (most recent call last):
  8.   File "<stdin>", line 1, in <module>
  9. IndexError: tuple index out of range
  10. >>> tuple1[0][1]
  11. 3
  12. >>> tuple1[2][2]
  13. Traceback (most recent call last):
  14.   File "<stdin>", line 1, in <module>
  15. IndexError: list index out of range
  16. >>> tuple2 = tuple1+[(3)]
  17. >>> tuple2
  18. [(2, 3), (4, 5), 3]
  19. >>> tuple2[2]
  20. 3
  21. >>> tuple2[2][0]
  22. Traceback (most recent call last):
  23.   File "<stdin>", line 1, in <module>
  24. TypeError: 'int' object is not subscriptable
复制代码





欢迎光临 51学通信论坛2017新版 (http://bbs.51xuetongxin.com/) Powered by Discuz! X3