Don't understand a part in code with append()
I have this python code: https://code.sololearn.com/cgUc8iACeWHc/?ref=app a, b = [], [] print("a:", a, "b:", b) for x in range(2): print("x:", x) print("a:", a) a.append(x) print("after a.append(x) a:", a) print("b:", b) b.append(a) print("after b.append(a) b:", b) After the first iteration of the loop with x = 0 the values are a = [0] and b = [[0]]. In the second iteration with x = 1 the value of a = [0,1] Up to this point I totally understand it. But now even before the execution of b.append(a) the value of b = [[0,1]]. But why? I would expect that it is still [[0]] because we have not executed a command regarding b in the second iteration of the loop. At the end b = [[0, 1], [0,1]]. I would expect [[0], [0,1]].