2014-08-12 19:41:18 +01:00
|
|
|
# test builtin range type
|
|
|
|
|
|
|
|
# print
|
|
|
|
print(range(4))
|
|
|
|
|
2015-04-05 00:03:43 +01:00
|
|
|
# bool
|
|
|
|
print(bool(range(0)))
|
|
|
|
print(bool(range(10)))
|
|
|
|
|
2014-08-12 19:41:18 +01:00
|
|
|
# len
|
|
|
|
print(len(range(0)))
|
|
|
|
print(len(range(4)))
|
|
|
|
print(len(range(1, 4)))
|
|
|
|
print(len(range(1, 4, 2)))
|
|
|
|
print(len(range(1, 4, -1)))
|
|
|
|
print(len(range(4, 1, -1)))
|
|
|
|
print(len(range(4, 1, -2)))
|
|
|
|
|
|
|
|
# subscr
|
|
|
|
print(range(4)[0])
|
|
|
|
print(range(4)[1])
|
|
|
|
print(range(4)[-1])
|
|
|
|
|
|
|
|
# slice
|
|
|
|
print(range(4)[0:])
|
|
|
|
print(range(4)[1:])
|
|
|
|
print(range(4)[1:2])
|
|
|
|
print(range(4)[1:3])
|
|
|
|
print(range(4)[1::2])
|
|
|
|
print(range(4)[1:-2:2])
|
2015-10-05 18:02:40 +01:00
|
|
|
print(range(1, 4)[:])
|
|
|
|
print(range(1, 4)[0:])
|
|
|
|
print(range(1, 4)[1:])
|
|
|
|
print(range(1, 4)[:-1])
|
|
|
|
print(range(7, -2, -4)[:])
|
2017-05-18 01:33:50 +01:00
|
|
|
print(range(1, 100, 5)[5:15:3])
|
|
|
|
print(range(1, 100, 5)[15:5:-3])
|
|
|
|
print(range(100, 1, -5)[5:15:3])
|
|
|
|
print(range(100, 1, -5)[15:5:-3])
|
2015-03-06 19:48:14 +00:00
|
|
|
|
2017-11-24 04:30:12 +00:00
|
|
|
# for this case uPy gives a different stop value but the listed elements are still correct
|
|
|
|
print(list(range(7, -2, -4)[2:-2:]))
|
|
|
|
|
2017-04-05 01:52:29 +01:00
|
|
|
# zero step
|
|
|
|
try:
|
|
|
|
range(1, 2, 0)
|
|
|
|
except ValueError:
|
|
|
|
print("ValueError")
|
|
|
|
|
2015-04-05 00:03:43 +01:00
|
|
|
# bad unary op
|
|
|
|
try:
|
|
|
|
-range(1)
|
|
|
|
except TypeError:
|
|
|
|
print("TypeError")
|
|
|
|
|
|
|
|
# bad subscription (can't store)
|
|
|
|
try:
|
|
|
|
range(1)[0] = 1
|
|
|
|
except TypeError:
|
|
|
|
print("TypeError")
|