2013-12-29 15:34:42 -07:00
|
|
|
# basic list functionality
|
|
|
|
x = [1, 2, 3 * 4]
|
|
|
|
print(x)
|
|
|
|
x[0] = 4
|
|
|
|
print(x)
|
|
|
|
x[1] += -4
|
|
|
|
print(x)
|
|
|
|
x.append(5)
|
|
|
|
print(x)
|
|
|
|
f = x.append
|
|
|
|
f(4)
|
|
|
|
print(x)
|
2014-01-11 15:51:05 -07:00
|
|
|
|
|
|
|
x.extend([100, 200])
|
|
|
|
print(x)
|
2014-04-12 18:20:10 -06:00
|
|
|
x.extend(range(3))
|
|
|
|
print(x)
|
2014-01-11 15:51:05 -07:00
|
|
|
|
|
|
|
x += [2, 1]
|
|
|
|
print(x)
|
2014-02-01 18:32:55 -07:00
|
|
|
|
|
|
|
print(x[1:])
|
|
|
|
print(x[:-1])
|
|
|
|
print(x[2:3])
|
2016-08-14 18:46:35 -06:00
|
|
|
|
|
|
|
# unsupported type on RHS of add
|
|
|
|
try:
|
|
|
|
[] + None
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|