circuitpython/tests/basics/builtin_reversed.py
Damien George bb91f1195a py: Improve range: add len, subscr, proper print.
Can now index ranges with integers and slices, and reverse ranges
(although reversing is not very efficient).

Not sure how useful this stuff is, but gets us closer to having all of
Python's builtins.
2014-08-12 19:41:18 +01:00

34 lines
542 B
Python

# test the builtin reverse() function
# list
print(list(reversed([])))
print(list(reversed([1])))
print(list(reversed([1, 2, 3])))
# tuple
print(list(reversed(())))
print(list(reversed((1, 2, 3))))
# string
for c in reversed('ab'):
print(c)
# bytes
for b in reversed(b'1234'):
print(b)
# range
for i in reversed(range(3)):
print(i)
# user object
class A:
def __init__(self):
pass
def __len__(self):
return 3
def __getitem__(self, pos):
return pos + 1
for a in reversed(A()):
print(a)