2014-01-03 19:26:30 -05:00
|
|
|
a = [1, 2, 3]
|
2014-01-05 08:44:06 -05:00
|
|
|
print(a.index(1))
|
|
|
|
print(a.index(2))
|
|
|
|
print(a.index(3))
|
|
|
|
print(a.index(3, 2))
|
2014-03-13 01:57:16 -04:00
|
|
|
print(a.index(1, -100))
|
|
|
|
print(a.index(1, False))
|
|
|
|
|
|
|
|
try:
|
|
|
|
print(a.index(1, True))
|
|
|
|
except ValueError:
|
|
|
|
print("Raised ValueError")
|
|
|
|
else:
|
|
|
|
print("Did not raise ValueError")
|
|
|
|
|
2014-01-05 08:44:06 -05:00
|
|
|
try:
|
|
|
|
print(a.index(3, 2, 2))
|
|
|
|
except ValueError:
|
|
|
|
print("Raised ValueError")
|
|
|
|
else:
|
|
|
|
print("Did not raise ValueError")
|
|
|
|
|
2014-01-03 19:26:30 -05:00
|
|
|
a = a + a
|
|
|
|
b = [0, 0, a]
|
|
|
|
print(a.index(2))
|
|
|
|
print(b.index(a))
|
|
|
|
print(a.index(2, 2))
|
2014-01-05 08:44:06 -05:00
|
|
|
|
2014-01-03 19:26:30 -05:00
|
|
|
try:
|
|
|
|
a.index(2, 2, 2)
|
|
|
|
except ValueError:
|
|
|
|
print("Raised ValueError")
|
|
|
|
else:
|
2014-01-05 08:44:06 -05:00
|
|
|
print("Did not raise ValueError")
|
2015-03-25 19:10:09 -04:00
|
|
|
|
|
|
|
# 3rd argument to index greater than length of list
|
|
|
|
print([1, 2].index(1, 0, 4))
|