Question: 6 -
Which of the following will give error?Suppose dict1={"a":1,"b":2,"c":3}
-
print(dict1.get("b"))
-
dict1["a"]=5
-
print(len(dict1))
-
None of these.
Answer:
None of these.
Solution not available.
Question: 7 -
Which of the following is False regarding dictionary in Python?dict={"Joey":1,"Rachel":2}
dict.update({"Phoebe":2})
print(dict)
-
None of the above
-
Values of a dictionary can be string,integers or combination of both.
-
The value of a dictionary can be accessed with the help of indices.
-
Keys of a dictionary can be string,integers or combination of both
Answer:
The value of a dictionary can be accessed with the help of indices.
Solution not available.
Question: 8 -
Which of the following will delete key_value pair for key="tiger" in dictionary?dic={"lion":"wild","tiger":"wild","cat":"domestic","dog":"domestic"}
-
del dic["tiger"]
-
del(dic.["tiger"])
-
delete(dic.["tiger"])
-
dic["tiger"].delete()
Answer:
del dic["tiger"]
Solution not available.
Question: 9 -
Which of the following Python codes will give same output if
(i) dict.pop("book")
(ii) del dict["book"]
(iii) dict.update({"diary":1,"novel":5})dict={"diary":1,"book":3,"novel":5}
-
i, ii
-
i, ii, iii
-
i, iii
-
ii, iii
Answer:
i, ii
Solution:
del dict["book"] and dict.pop("book") are thefollowing Python codes will give same output.
del dict["book"] and dict.pop("book") are thefollowing Python codes will give same output.
Question: 10 -
What will be the following Python code?dict1={"a":10,"b":2,"c":3}
str1=""
for i in dict1:
str1=str1+str(dict1[i])+" "
str2=str1[:-1]
print(str2[::-1])
-
Error
-
3, 2, 01
-
3, 2
-
3, 2, 10
Answer:
3, 2, 01