0

Came across below lines of codes:

first_names = ['Fred', 'George', 'Bill']
last_names = ['Smith', 'Jones', 'Williams']
name_tuple = (first_names, last_names)

first_names.append('Igor')
#name_tupple why this output
#(['Fred', 'George', 'Bill', 'Igor'], ['Smith', 'Jones', 'Williams'])
  • If tuple is immutable why tuple referenced get change on appending new item to list?

i know tuple have reference of list and list is immutable in python.

why dont make tuple a copy of elements that can be constant through out?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
pylist
  • 349
  • 3
  • 6

1 Answers1

-1

You said it: you have a tuple of references to lists. The references are not changing, only the lists are. As Henrik Andersson pointed out in comments, this answer explains it very well.

RishiG
  • 2,790
  • 1
  • 14
  • 27