0
Why am i getting this error?
i am trying to access a list within a list so i do somthing like this: Lst = [[O,O],[O,O],[O,O]] Lst[2][1] Then it tells me that this: Lst[2][1] is invalid syntax i dont understand...
7 Answers
+ 2
i tried your code. at first, i got an error sayin "O is not defined"
so i changed all the numbers.
then again after using print(), i got the output. so use this code::
Lst=[[0,0],[0,0],[0,0]]
print(Lst[2][1])
+ 1
if you think about it, you'll see that arrays are variables or memory spaces. just like any other variable, you can't just call the variable to do nothing. it like having int a = 2 on one line and then on the next line have just a. the program will ask you, "what the heck should I do with a?" that's why @parth's program didn't complain cause of using the array with a print statement
+ 1
if you think about it, you'll see that arrays are variables or memory spaces. just like any other variable, you can't just call the variable to do nothing. it like having int a = 2 on one line and then on the next line have just a. the program will ask you, "what the heck should I do with a?" that's why @parth's program didn't complain cause of using the array with a print statement
0
Lst[2][1] is not valid as you are only traversing the value but not showing it anywhere or using it somewhere else
Try printing the value and it will work!
0
In addition to what Parth Krishna said:
the items you are using in the list are characters, which should be specified like this: Lst=[['0','0'],['0','0'],['0','0']].
If you don't do this, you will still have an error:
Lst = [[O,O],[O,O],[O,O]]
NameError: name 'O' is not defined
0
that's just one of many Python bugs. If you want access a list within a list you need one more variable:
new_lst = Lst[2]
print new_lst[1]
0
that's just one of many Python bugs. If you want access a list within a list you need one more variable:
new_lst = Lst[2]
print new_lst[1]