0
How can i creat a 2D array that the user can put its informations?
1 Antwort
+ 2
A list can contain any type of object, including other lists. So a 2d 'array' (we still call them lists in Python) would look like this:
two_dim = [ [1, 2], [3, 4] ]
You can initially make the inner lists empty too.
two_dim_empty = [ [], [] ]
To reference the first element in the second sublist:
two_dim[1][0] #3
To add an element to the first sublist:
two_dim[0].append(5)
the sublists do not need to be the same size, it is in fact fully dynamic
and finally you can append a value that you get from the user by the input() statement