So, I've been trying to create a matrix consisting of multiplication tables up to n with python.
my function goes like this:
def multiplicationTable(n):
tablePrint = []
tempTable = []
for s in range(n):
s += 1
tempTable.clear()
for r in range(n):
r += 1
tempTable.append(r*s)
tablePrint.append(tempTable)
# print(tablePrint)
return tablePrint
However, the returned list consists of n versions of the nth tempTable. If you remove the comment, you can see that through each iteration, every single instance within tablePrint gets edited. I had a friend explain roughly that lists are not data, but a memory address to a set of data, is this why this doesn't work?