+ 2
In a dictionary can we access the elements of this ..... Here it is-------- dic= {1:10,2:20,3:30,4:40}
3 odpowiedzi
+ 3
You can access to the elements using the key. For example, if you want to check the values for each key i would do It so:
print dic[1]
print dic[2]
etc...
You can even change the values of the elements assigned to the Keys. Ex:
dic[1]=5
(You have changed the value associated to the key 1 to 5 when at the beggining it was 10.
But you can never change the Keys.
This is a good example: https://youtu.be/DSzqe4Rb5YY
0
Doesn't dic[1] refer to the second key in the dictionary? In your example
dic[1]=5
would mean that the dictionary is changed to:
-- dic={1:10,2:5,3:30,4:40}
Or am I wrong?
0
This is not a list.
As he gave to the key 1 the value 10
dic[1]=10
When you give 5 as value of the key 1
dic[1] = 5
It will be:
dic = {1:5,...}
because dictonaries are not indicized, even if in this example ot starts from 1. The key can be a string ...