0

Example:

t1=(1,2,3,4)

t2=(5,6,7,8)

print(len(t1)) #Prints: 4

concatenating two tuples

t1=t1+t2

print(t1) #Prints:(1,2,3,4,5,6,7,8)

print(len(t1)) #Prints: 8

repeatation of tuple

t1=t1*3

print(t1) #Prints: (1,2,3,4,1,2,3,4,1,2,3,4)

len(t1) #Prints: 12

Here, in the below code snippet we can see the length of the tuple been changed. Hence, the memory declared for the tuple initially is changed. Please explain this behavior of tuples.

Community
  • 1
  • 1
  • 3
    The tuple was not changed. The name `t1` was pointed at a new tuple. – Stephen Rauch Jun 06 '18 at 04:38
  • The tuple object is not changed. You've created *new tuple objects* and re-assigned them to the same variable. Use a different variable and you'll see this is so. Note, this is *also the case with list objects* when using concatenation and repetition. And of course, this is the case when you use the `+` and `*` operators with all the numeric types in Python, which are immutable as well. – juanpa.arrivillaga Jun 06 '18 at 04:46

0 Answers0