You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
381 B
28 lines
381 B
# test list slices, getting values
|
|
|
|
x = list(range(10))
|
|
a = 2
|
|
b = 4
|
|
c = 3
|
|
print(x[:])
|
|
print(x[::])
|
|
print(x[::c])
|
|
print(x[:b])
|
|
print(x[:b:])
|
|
print(x[:b:c])
|
|
print(x[a])
|
|
print(x[a:])
|
|
print(x[a::])
|
|
print(x[a::c])
|
|
print(x[a:b])
|
|
print(x[a:b:])
|
|
print(x[a:b:c])
|
|
|
|
# these should not raise IndexError
|
|
print([][1:])
|
|
print([][-1:])
|
|
|
|
try:
|
|
[][::0]
|
|
except ValueError:
|
|
print('ValueError')
|
|
|