Question: 1 -
Which of the following is correct with respect to above Python code?d={"a":3,"b":7}
-
3 and 7 are the values of dictionary d
-
a dictionary d is created.
-
All of the above.
-
a and b are the keys of dictionary d.
Answer:
All of the above.
Solution not available.
Question: 2 -
What will be the result of above Python code?dict={"Joey":1,"Rachel":2}
dict.update({"Phoebe":2})
print(dict)
-
{"Joey":1,"Rachel":2,"Phoebe":2}
-
{"Joey":1,"Rachel":2}
-
Error
-
{"Joey":1,"Phoebe":2}
Answer:
{"Joey":1,"Rachel":2,"Phoebe":2}
Solution not available.
Question: 3 -
What will be the output of above Python code?d1={"abc":5,"def":6,"ghi":7}
print(d1[0])
-
5
-
Error
-
abc
-
{"abc":5}
Answer:
Error
Solution:
The above code will contain an error. Because 0 is not a key abc, def and ghi are keys to the dictionary.
The above code will contain an error. Because 0 is not a key abc, def and ghi are keys to the dictionary.
Question: 4 -
What will the above Python code do?dict={"Phy":94,"Che":70,"Bio":82,"Eng":95}
dict.update({"Che":72,"Bio":80})
-
It will simply update the dictionary as dict={"Phy":94,"Che":72,"Bio":80,"Eng":95}
-
It will throw an error as dictionary cannot be updated.
-
It will create new dictionary as dict={"Che":72,"Bio":80} and old dict will be deleted.
-
It will not throw any error but it will not do any changes in dict
Answer:
It will simply update the dictionary as dict={"Phy":94,"Che":72,"Bio":80,"Eng":95}
Solution not available.
Question: 5 -
Which one of the following is correct?
-
In python, a dictionary can have two same keys with different values.
-
In python, a dictionary can neither have two same keys nor two same values.
-
In python, a dictionary can have two same values with different keys
-
In python, a dictionary can have two same keys or same values but cannot have two same key-value pair
Answer:
In python, a dictionary can have two same values with different keys