0

If you run this code, then both outputs are the same: ['A','B',' ',' ']. Don't know what I am doing wrong but shouldn't the output of array2 be blank: [' ',' ',' ',' '] and array1 should be: ['A','B',' ',' ']?

reset = [" "," "," "," "]

array1 = []
array2 = []

array1.append([" "," "," "," "])
array2 = array1

array1[0][0] = "A"
array1[0][1] = "B"

print (array1)
print (array2)
Ted Klein Bergman
  • 9,146
  • 4
  • 29
  • 50
Demyan
  • 11
  • 1
    You're setting `array2 = array1`, so they both point to the exact same list and will therefore be the same. Did you mean to do `array2 = reset`? – Ted Klein Bergman Feb 23 '21 at 21:20
  • `array2 = array1` **does not** create a copy of your array. It simply instructs both variables to point to the same object (i.e. array). – PM 77-1 Feb 23 '21 at 21:21

0 Answers0