I am trying to append a list to a list using an append function. See the below code - the temp will be a temporary list which is created dynamically. I want to append temp to list1.
temp = []
list1 = []
for num in range(0,2):
temp.clear()
temp.append(num)
list1.append(temp)
print(list1)
The output intended in list1 is [[0],[1]]. However i get [[1],[1]]. Can some one explain the reason behind this. Append should append to a list with out changing the list.