The simplest way is
test = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
But, if you want to have more number of lists to be created then you might want to go with list comprehension, like this
test = [[1, 2, 3] for i in range(100)]
This will create a list of 100 sub lists. The list comprehension is to create a new list and it can be understood like this
test = []
for i in range(100):
test.append([1, 2, 3])
Note: Instead of doing test[0] = ...
, you can simply make use of list.append
like this
test = []
test.append([1, 2, 3])
...
If you look at the language definition of list,
list_display ::= "[" [expression_list | list_comprehension] "]"
So, a list can be constructed with list comprehension or expression list. If we see the expression list,
expression_list ::= expression ( "," expression )* [","]
It is just a comma separated one or more expressions.
In your case,
1[1, 2, 3], 2[1, 2, 3] ...
are not valid expressions, since 1[1, 2, 3]
has no meaning in Python. Also,
1 = [1, 2, 3]
means you are assigning [1, 2, 3]
to 1
, which is also not a valid expression. That is why your attempts didn't work.