Lichen

Annotated tests/tuple.py

805:7f3f57fdc053
2017-04-08 Paul Boddie Added the bin built-in function.
paul@227 1
l = (1, 2, 3, "four")
paul@266 2
print len(l)            # 4
paul@266 3
print l[0]              # 1
paul@266 4
print l[1]              # 2
paul@266 5
print l[2]              # 3
paul@266 6
print l[3]              # four
paul@266 7
print l[-1]             # four
paul@266 8
print l[-2]             # 3
paul@266 9
print l[-3]             # 2
paul@266 10
print l[-4]             # 1
paul@266 11
print l                 # (1, 2, 3, "four")
paul@227 12
paul@227 13
l = [1, 2, 3, "four"]
paul@227 14
t = tuple(l)
paul@266 15
print t                 # (1, 2, 3, "four")
paul@266 16
paul@266 17
try:
paul@266 18
    print t[4]          # should raise an exception
paul@266 19
except IndexError, exc:
paul@266 20
    print "t[4]: failed with argument", exc.index
paul@266 21
paul@266 22
try:
paul@266 23
    print t[-5]         # should raise an exception
paul@266 24
except IndexError, exc:
paul@266 25
    print "t[-5]: failed with argument", exc.index