Let us say, we have a Tuple that contains three names, 'Mohan', 'Kriti' and 'Salim'. And we have a second Tuple with two names 'Sia' and 'Andrew'. And we want to join them.
It can be achieved by using the '+' operator
x = ("Mohan", "Kriti", "Salim") y = ("Sia", "Andrew") z = x + y print(z)
So, in the above code we have created a 'Tuple' and initialised to the variable 'x'.
Below is how the values are positioned in the Tuple,
Also we have another Tuple that contains, 'Sia' and 'Andrew'.
Next, we have used the '+' operator to add the the Tuples 'x' and 'y'.
And the Tuples 'x' and 'y' is joined and initialised to a new Tuple 'z'.
And we get the below output,
Let us say, we have a 'Tuple' that contains three names, 'Mohan', 'Kriti' and 'Salim'. And we want to repeat the names two times and assign to another 'Tuple'.
It can be achieved by using the '*' operator
x = ("Mohan", "Kriti", "Salim") y = x * 2 print(y)
So, in the above code we have created a 'Tuple' and initialised to the variable 'x'.
Below is how the values are positioned in the Tuple,
Next, we have used the '*' operator to repeat each element of the Tuple 'x' two times.
And the elements of the Tuple 'x' is repeated 2 times and initialised to a new Tuple 'y'.
And we get the below output,
Where 'Mohan', 'Kriti' and 'Salim' is repeated twice.