circuitpython/tests/basics/builtin_slice.py

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

44 lines
552 B
Python
Raw Normal View History

# test builtin slice
# print slice
class A:
def __getitem__(self, idx):
print(idx)
return idx
s = A()[1:2:3]
# check type
print(type(s) is slice)
2017-02-24 09:13:56 -05:00
s = slice(10)
print(s)
s = slice(0, 4)
print(s)
s = slice(0, 4, 2)
print(s)
s = slice(-1)
print(s)
print(s.indices(10))
s = slice(-5, -1)
print(s)
print(s.indices(10))
s = slice(-100, -2, -1)
print(s)
print(s.indices(10))
s = slice(None, None, -2)
print(s)
print(s.indices(10))
s = slice(-100, -2, 0)
print(s)
try:
print(s.indices(10))
except Exception as e:
print(e)