In [1]:
t = (0, 1, 2)
In [2]:
print(t)
In [3]:
print(type(t))
In [4]:
print(t[0])
In [5]:
print(t[:2])
In [6]:
# t[0] = 100
# TypeError: 'tuple' object does not support item assignment
In [7]:
# t.append(100)
# AttributeError: 'tuple' object has no attribute 'append'
In [8]:
t_add = t + (3, 4, 5)
In [9]:
print(t_add)
In [10]:
print(t)
In [11]:
# print(t + [3, 4, 5])
# TypeError: can only concatenate tuple (not "list") to tuple
In [12]:
t_add_one = t + (3,)
In [13]:
print(t_add_one)
In [14]:
l = list(t)
In [15]:
print(l)
In [16]:
print(type(l))
In [17]:
l.insert(2, 100)
In [18]:
print(l)
In [19]:
t_insert = tuple(l)
In [20]:
print(t_insert)
In [21]:
print(type(t_insert))
In [22]:
l = list(t)
l[1] = 100
t_change = tuple(l)
In [23]:
print(t_change)
In [24]:
l = list(t)
l.remove(1)
t_remove = tuple(l)
In [25]:
print(t_remove)