+ 2
Why does this python code gives an error?
list = [1,[2,3],(4,5),False,"No"] print (list[1[1]])
4 ответов
+ 7
The way you use the index to access the list is the issue here. Use this:
list = [1,[2,3],(4,5),False,"No"]
print (list[1][1]) #<-- this is ok!
#print (list[1[1]])
# output = 3
+ 2
You have to change it to print(list[1][1]) instead of pribt(list[1[1]])
+ 2
Okay, thanks.
+ 2
Just to clarify, list[1[1]] gives you an error because you're trying to access a value, in index 1, inside the value 1, when you do 1[1]. This raises an error, given that int type values do not support indexing.
For the actual behavior you desire, as you already know, go with the already written answers.
Happy coding!