micropython/tests/basics/list_slice.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
424 B
Python
Raw Normal View History

# test list slices, getting values
2014-04-02 14:23:04 +01:00
x = list(range(10))
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[::])
print(x[::c])
2014-04-02 14:23:04 +01:00
print(x[:b])
print(x[:b:])
print(x[:b:c])
2014-04-02 14:23:04 +01:00
print(x[a])
print(x[a:])
print(x[a::])
print(x[a::c])
2014-04-02 14:23:04 +01:00
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')