In this code I'm adding zeros to an empty list, then when it contains 9 zeros that list is added to another list which is called board, then I clear the row of 9 zeros and repeat the process 9 times again:
row = []
for i in range(9):
for j in range(9):
row.append('0')
self.board.append(row)
row.clear()
print(board)
After some prints I've understand that before the outer loop ends the board contains all 9 rows of 9 zeros but when row.clear()
is executed for the last time it clears all the rows of zeros giving me a result of a list that contains 9 empty lists, which of course is not what I want, I know how to solve it but I don't understand why when the loop reaches the end all internal lists of zeros are clear.