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
  • 230,875
  • 49
  • 477
  • 553
pylist
  • 259
  • 2
  • 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,630
  • 1
  • 12
  • 27