2014-05-10 20:23:00 +01:00
|
|
|
# test slices; only 2 argument version supported by Micro Python at the moment
|
|
|
|
x = list(range(10))
|
|
|
|
|
|
|
|
# Assignment
|
|
|
|
l = list(x)
|
|
|
|
l[1:3] = [10, 20]
|
|
|
|
print(l)
|
|
|
|
l = list(x)
|
|
|
|
l[1:3] = [10]
|
|
|
|
print(l)
|
|
|
|
l = list(x)
|
|
|
|
l[1:3] = []
|
|
|
|
print(l)
|
2014-05-10 21:03:30 +01:00
|
|
|
l = list(x)
|
|
|
|
del l[1:3]
|
|
|
|
print(l)
|
2014-05-10 20:23:00 +01:00
|
|
|
|
|
|
|
l = list(x)
|
|
|
|
l[:3] = [10, 20]
|
|
|
|
print(l)
|
|
|
|
l = list(x)
|
|
|
|
l[:3] = []
|
|
|
|
print(l)
|
2014-05-10 21:03:30 +01:00
|
|
|
l = list(x)
|
|
|
|
del l[:3]
|
|
|
|
print(l)
|
2014-05-10 20:23:00 +01:00
|
|
|
|
|
|
|
l = list(x)
|
|
|
|
l[:-3] = [10, 20]
|
|
|
|
print(l)
|
|
|
|
l = list(x)
|
|
|
|
l[:-3] = []
|
|
|
|
print(l)
|
2014-05-10 21:03:30 +01:00
|
|
|
l = list(x)
|
|
|
|
del l[:-3]
|
|
|
|
print(l)
|
2017-02-20 04:09:59 +00:00
|
|
|
|
|
|
|
# assign a tuple
|
|
|
|
l = [1, 2, 3]
|
|
|
|
l[0:1] = (10, 11, 12)
|
|
|
|
print(l)
|
|
|
|
|
|
|
|
# RHS of slice must be an iterable
|
|
|
|
try:
|
|
|
|
[][0:1] = 123
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|