Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




PYTHON - COPY FROM TUPLE


How to copy one Tuple to the other ?


We can use the 'tuple( )' constructor(We will explain it later) to make a copy of the Tuple .


Example :


x = ("Mohan", "Kriti", "Salim")
y = tuple(x)
print("The Copied Tuple is ",y) 


Output :



  The Copied Tuple is ('Mohan', 'Kriti', 'Salim')

So , in the above code we have created a 'Tuple' and initialised to the variable 'x' .


x = ["Mohan", "Kriti", "Salim"]

Below is how the values are positioned in the Tuple ,


java_Collections

Then we have used the 'tuple( )' constructor to take the Tuple 'x' as parameter and create a new Tuple that would be the exact copy of 'x' .


Then assign it to 'y' .


y = tuple(x)

java_Collections

And we get the below output ,


The Copied Tuple is ('Mohan', 'Kriti', 'Salim')

Note : Do not use the '=' operator to copy a Tuple to the other(i.e. If there are two Tuples 'x' and 'y'. Do not use y = x). Because in that case any changes made to the Tuple 'x' will be reflected in the copied Tuple 'y'.