2015-04-04 17:05:30 -04:00
|
|
|
# test builtin slice
|
|
|
|
|
|
|
|
# print slice
|
|
|
|
class A:
|
|
|
|
def __getitem__(self, idx):
|
|
|
|
print(idx)
|
2016-10-21 23:39:03 -04:00
|
|
|
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)
|