Creating Tuples


In [ ]:
# This is some IPython %magic
%xmode plain

In [ ]:
# with initial values
t = ('foo', 1, object())
print t

In [ ]:
u = tuple(['foo', 1234, object()])
print u

Tuples are Immutable


In [ ]:
t[0] = 'bar'

In [ ]:
t.append('bar')

In [ ]:
del(t[0])

In [ ]:
x = list(['a', 'b', 'c'])
y = x
x += ['d']
print x
print y

In [ ]:
x = tuple(['a', 'b', 'c'])
y = x
x += ('d',)
print x
print y

Inspecting, Just Like Lists


In [ ]:
x = ('a', 'b', 'c', 'd')
print len(x)
print x[0]
print x[-2:]
print 'a' in x