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