Damien George
8 years ago
1 changed files with 11 additions and 5 deletions
@ -1,22 +1,28 @@ |
|||||
# test slices; only 2 argument version supported by Micro Python at the moment |
# test list slices, getting values |
||||
|
|
||||
x = list(range(10)) |
x = list(range(10)) |
||||
a = 2 |
a = 2 |
||||
b = 4 |
b = 4 |
||||
c = 3 |
c = 3 |
||||
print(x[:]) |
print(x[:]) |
||||
print(x[::]) |
print(x[::]) |
||||
#print(x[::c]) |
print(x[::c]) |
||||
print(x[:b]) |
print(x[:b]) |
||||
print(x[:b:]) |
print(x[:b:]) |
||||
#print(x[:b:c]) |
print(x[:b:c]) |
||||
print(x[a]) |
print(x[a]) |
||||
print(x[a:]) |
print(x[a:]) |
||||
print(x[a::]) |
print(x[a::]) |
||||
#print(x[a::c]) |
print(x[a::c]) |
||||
print(x[a:b]) |
print(x[a:b]) |
||||
print(x[a:b:]) |
print(x[a:b:]) |
||||
#print(x[a:b:c]) |
print(x[a:b:c]) |
||||
|
|
||||
# these should not raise IndexError |
# these should not raise IndexError |
||||
print([][1:]) |
print([][1:]) |
||||
print([][-1:]) |
print([][-1:]) |
||||
|
|
||||
|
try: |
||||
|
[][::0] |
||||
|
except ValueError: |
||||
|
print('ValueError') |
||||
|
Loading…
Reference in new issue