- 2016.07.14 Thursday
- Pythonのリスト の ネガティブインデックス(負のインデックス)の不思議
-
Pythonのリスト の ネガティブインデックス(負のインデックス)の不思議
>>> x = [1, 2, 3.0, "a", "b", "c"]
ネガティブインデックス(負のインデックス)
>>> x[-1]
'c' // x = [1, 2, 3.0, "a", "b", "c"]
>>> x[-2]
'b' // x = [1, 2, 3.0, "a", "b", "c"]
>>> x[-3]
'a' // x = [1, 2, 3.0, "a", "b", "c"]
>>> x[-4]
3.0 // x = [1, 2, 3.0, "a", "b", "c"]
>>> x[-5]
2 // x = [1, 2, 3.0, "a", "b", "c"]
>>> x[-6]
1 // x = [1, 2, 3.0, "a", "b", "c"]
>>> x[-7]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
http://tsugu76.hatenablog.com/entry/2014/04/25/075538
より
- | whaison | Python | 16:29 | comments(0) | - | pookmark |
- Comment