Lichen

tests/tuple.py

1038:e3d77b4d9fa8
5 months ago Paul Boddie Merged changes from the trailing-data branch. value-replacement
     1 l = (1, 2, 3, "four")     2 print len(l)            # 4     3 print l[0]              # 1     4 print l[1]              # 2     5 print l[2]              # 3     6 print l[3]              # four     7 print l[-1]             # four     8 print l[-2]             # 3     9 print l[-3]             # 2    10 print l[-4]             # 1    11 print l                 # (1, 2, 3, "four")    12     13 l = [1, 2, 3, "four"]    14 t = tuple(l)    15 print t                 # (1, 2, 3, "four")    16     17 try:    18     print t[4]          # should raise an exception    19 except IndexError, exc:    20     print "t[4]: failed with argument", exc.index    21     22 try:    23     print t[-5]         # should raise an exception    24 except IndexError, exc:    25     print "t[-5]: failed with argument", exc.index    26     27 a, b, c, d = l    28 print a, b, c, d        # 1 2 3 "four"    29     30 try:    31     a, b, c = l    32 except ValueError, exc:    33     print "a, b, c = l: failed with length", exc.value    34     35 # Add tuples together.    36     37 m = ("five", 6, 7, 8)    38 n = t + m    39 print n                 # (1, 2, 3, "four", "five", 6, 7, 8)    40     41 # Add to list, really testing tuple iteration.    42     43 o = l + m    44 print o                 # [1, 2, 3, "four", "five", 6, 7, 8]    45     46 try:    47     print t + l         # should raise an exception    48 except TypeError:    49     print "t + l: failed due to tuple-list addition"