0
Why i have an error when I try to print the second item in the next code? (Python)
house = {red: 12 , blue: 14} print (house[house[2]])
4 odpowiedzi
+ 3
Jan Markus nope we're both wrong
I ran the code and it was a name error
unless that's what you're saying and I'm just really dumb
+ 2
Array or dictionary indexes start with 0, so the second would be the index 1.
+ 1
Rrr Is that your total code?
You defined house as dictionary.. and also wrong keys ,that red,blue are not defined... may be you mean "red", "blue" .. strings.
It is not an array .. so you should access it by its keys not indexes..
edit:
house = {"red": 12 , "blue": 14}
print (house["blue"])
0
Then only i can look for the keys for the name and not for the index?