0

I have some questions about the below code and it's respective output.

Code:

x = [5,6] 
y = x 
y.append(6) 
print(x,y)

Output: [5,6,6] [5,6,6]

My Question: Why is the value of x equal to y?
Can anyone explain the logic behind this output.

SherylHohman
  • 16,580
  • 17
  • 88
  • 94

1 Answers1

0

In python variables data values through references. A reference is a name that refers to the specific location in memory of a value (object). References take the form of variables, attributes, and items.data values through references. A reference is a name that refers to the specific location in memory of a value (object). References take the form of variables, attributes, and items.