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