0

probably a silly question by I can't figure it out myself so here it goes. I'm trying to duplicate a variable so that when the original variable changes it's value, the copy changes as well. I've tried it this way but it's clearly not working:

x = 10
y = x
x = 20
y
10

how do I make y to equal 20 only by changing x?

tnx

Kuper
  • 83
  • 6

1 Answers1

0

That depends on the type of the object, and whether the object is mutable or immutable. Since you values are integers, you can't. It would work if, for example, they were lists.

blue_note
  • 27,712
  • 9
  • 72
  • 90