Modifying Elements in Python
As you already know, a tuple is an immutable data type. If we try to access its element by index and assign it a different value, we will get an error:
tpl = ('a', 'b', 'c')
tpl[0] = '!'
print(tpl) # will display an error
The following code is given:
tpl = ('ab', 'cd', 'ef')
print(tpl[1])
Tell me what will be output to the console.
The following code is given:
tpl = (4, 6, 8, 10)
res = tpl[-1] + tpl[0]
tpl[1] = res
print(res)
Tell me what will be output to the console.