In [50]:
# empty tuple
t = tuple()
# or
t = ()
In [52]:
# non-empty tuple
t = (0,1)
In [53]:
# get its length
len(t)
Out[53]:
In [54]:
# one element tuple
t = (0,)
In [74]:
# create tuples
t1 = (1,2,3)
t2 = (4,5,6)
t = t1+t2
t3 = 6,7,8
print "t = %s and t3=%s" % (t, t3)
In [62]:
# get the second element
t[1]
Out[62]:
In [63]:
# get the nex to last element
t[-2]
Out[63]:
In [75]:
# slice the tuple
t[1:4]
Out[75]:
In [65]:
# this wont work
t.count(3)
Out[65]:
In [76]:
# safe as for list
t.index(3)
Out[76]:
In [71]:
# min and max
min(t), min(t)
Out[71]:
In [42]:
# tuple from a list
t = tuple([1,2,3,4])
Out[42]:
In [ ]:
t + (5,)