In [68]:
# This is some IPython %magic
%xmode plain
In [69]:
# with initial values
m = ['foo', 1, object()]
print m
In [70]:
n = list('foo', 1, object())
In [71]:
n = list(['foo', 1234, object()])
print n
In [72]:
m[0] = 'bar'
print m
In [73]:
m.append('baz')
print m
In [74]:
q = ['y', 'z']
o = ['a', 'b', 'c']
o.append(q)
print o
In [75]:
p = ['1', '2', '3']
p.extend(q)
print p
In [76]:
r = ['a', 'b']
r + q
Out[76]:
In [77]:
r * 3
Out[77]:
In [78]:
del(p[2])
print p
In [79]:
print m[0]
print m[1]
In [80]:
# indices are integers
m['nope']
In [81]:
# out of bounds
m[9]
In [82]:
m[-3]
Out[82]:
In [83]:
from string import ascii_lowercase
letters = list(ascii_lowercase)
print letters
In [84]:
print letters[0:6]
In [85]:
print letters[:13]
print letters[13:]
In [86]:
print letters[-3:]
print letters[:-3]
In [87]:
print letters[-10:23]
In [88]:
print letters[:]
In [89]:
print letters[::2]
print letters[0:7:3]
In [90]:
'f' in letters
Out[90]:
In [91]:
'F' in letters
Out[91]:
In [92]:
letters.index('m')
Out[92]:
In [93]:
letters.index('M')
In [94]:
len(letters)
Out[94]:
In [97]:
a, b, c = [1, 2, 3]
print a
print b
print c
In [99]:
x = [10, 20, 30]
d, e, f = x
print d
print e
print f
In [101]:
sun, mon, tue, wed, thu, fri, sat = range(7) # <- actually an "iterator" in python 3
print sun
print sat