In [1]:
l = [0, 1, 2]
print(l)
print(type(l))
In [2]:
t = ('one', 'two', 'three')
print(t)
print(type(t))
In [3]:
r = range(10)
print(r)
print(type(r))
In [4]:
tl = list(t)
print(tl)
print(type(tl))
In [5]:
rl = list(r)
print(rl)
print(type(rl))
In [6]:
lt = tuple(l)
print(lt)
print(type(lt))
In [7]:
rt = tuple(r)
print(rt)
print(type(rt))
In [8]:
# t[0] = 'ONE'
# TypeError: 'tuple' object does not support item assignment
In [9]:
tl = list(t)
tl[0] = 'ONE'
t_new = tuple(tl)
print(t_new)
print(type(t_new))
In [10]:
t2 = t + ('four', 'five')
print(t)
print(t2)
In [11]:
# t2 = t + ('four')
# TypeError: can only concatenate tuple (not "str") to tuple
In [12]:
t2 = t + ('four', )
print(t)
print(t2)
In [13]:
tl = list(t)
tl.insert(2, 'XXX')
t_new = tuple(tl)
print(t_new)
print(type(t_new))