Sobes.tech
Middle

x = (1, 2, 3); y = x; y.append(4) What will happen?

sobes.tech AI

Answer from AI

In Python, tuples are immutable objects. In the code:

x = (1, 2, 3)
y = x
y.append(4)

an AttributeError will occur because tuples do not have an append method. The append method exists for lists, but not for tuples. If you need to add an element, you should create a new tuple, for example:

x = (1, 2, 3)
y = x + (4,)