2014-02-01 18:42:07 -07:00
|
|
|
# basic tuple functionality
|
|
|
|
x = (1, 2, 3 * 4)
|
|
|
|
print(x)
|
|
|
|
try:
|
|
|
|
x[0] = 4
|
|
|
|
except TypeError:
|
|
|
|
print("TypeError")
|
|
|
|
print(x)
|
|
|
|
try:
|
|
|
|
x.append(5)
|
|
|
|
except AttributeError:
|
|
|
|
print("AttributeError")
|
|
|
|
|
|
|
|
print(x[1:])
|
|
|
|
print(x[:-1])
|
|
|
|
print(x[2:3])
|
2014-02-08 14:17:51 -07:00
|
|
|
|
|
|
|
print(x + (10, 100, 10000))
|
2016-08-14 18:46:02 -06:00
|
|
|
|
2017-04-04 20:38:18 -06:00
|
|
|
# inplace add operator
|
|
|
|
x += (10, 11, 12)
|
|
|
|
print(x)
|
|
|
|
|
2016-08-14 18:46:02 -06:00
|
|
|
# construction of tuple from large iterator (tests implementation detail of uPy)
|
|
|
|
print(tuple(range(20)))
|
|
|
|
|
|
|
|
# unsupported unary operation
|
|
|
|
try:
|
|
|
|
+()
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|
|
|
|
|
|
|
|
# unsupported type on RHS of add
|
|
|
|
try:
|
|
|
|
() + None
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|