Tuple concatenation
It is possible to concatenate tuples to create a new object (concatenation, similar to strings).
1
2
3
4
|
x = (1,2,3,4)
y = (5,6,7,8)
z = x + y
print(z) # (1, 2, 3, 4, 5, 6, 7, 8)
|
During the multiplication operation, the tuple is repeated several times (similar to string multiplication).
1
2
3
|
x = (1,2,3,4)
z = x*2
print(z) # (1, 2, 3, 4, 1, 2, 3, 4)
|
Removing a tuple
Tuple operations and methods are similar to list operations and methods. Except for those that change the elements of a tuple.
An element contained in a
tuple
cannot be added or removed due to immutability. However, the tuple itself can be deleted using the
del
operator.
1
2
|
student = (2007, 'Ivan', 'Ivanov', '9-A', False)
del student
|