2016-11-25 22:39:25 -07:00
|
|
|
# test list slices, getting values
|
|
|
|
|
2014-04-02 07:23:04 -06:00
|
|
|
x = list(range(10))
|
|
|
|
a = 2
|
|
|
|
b = 4
|
|
|
|
c = 3
|
|
|
|
print(x[:])
|
|
|
|
print(x[::])
|
2016-11-25 22:39:25 -07:00
|
|
|
print(x[::c])
|
2014-04-02 07:23:04 -06:00
|
|
|
print(x[:b])
|
|
|
|
print(x[:b:])
|
2016-11-25 22:39:25 -07:00
|
|
|
print(x[:b:c])
|
2014-04-02 07:23:04 -06:00
|
|
|
print(x[a])
|
|
|
|
print(x[a:])
|
|
|
|
print(x[a::])
|
2016-11-25 22:39:25 -07:00
|
|
|
print(x[a::c])
|
2014-04-02 07:23:04 -06:00
|
|
|
print(x[a:b])
|
|
|
|
print(x[a:b:])
|
2016-11-25 22:39:25 -07:00
|
|
|
print(x[a:b:c])
|
2015-01-29 07:56:09 -07:00
|
|
|
|
|
|
|
# these should not raise IndexError
|
|
|
|
print([][1:])
|
|
|
|
print([][-1:])
|
2016-11-25 22:39:25 -07:00
|
|
|
|
|
|
|
try:
|
|
|
|
[][::0]
|
|
|
|
except ValueError:
|
|
|
|
print('ValueError')
|