Quiz: Dictionary

To View Tricks: Login Required

Number of Questions: 10

Question: 1 -

Which of the following is correct with respect to above Python code?

d={"a":3,"b":7}

Options:
  1. 3 and 7 are the values of dictionary d

  2. a dictionary d is created.

  3. All of the above.

  4. a and b are the keys of dictionary d.

  5. 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)

Options:
  1. {"Joey":1,"Rachel":2,"Phoebe":2}

  2. {"Joey":1,"Rachel":2}

  3. Error

  4. {"Joey":1,"Phoebe":2}

  5. 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])

Options:
  1. 5

  2. Error

  3. abc

  4. {"abc":5}

  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.


Question: 4 -

What will the above Python code do?

dict={"Phy":94,"Che":70,"Bio":82,"Eng":95}
dict.update({"Che":72,"Bio":80})

Options:
  1. It will simply update the dictionary as dict={"Phy":94,"Che":72,"Bio":80,"Eng":95}

  2. It will throw an error as dictionary cannot be updated.

  3. It will create new dictionary as dict={"Che":72,"Bio":80} and old dict will be deleted.

  4. It will not throw any error but it will not do any changes in dict

  5. 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?

Options:
  1. In python, a dictionary can have two same keys with different values.

  2. In python, a dictionary can neither have two same keys nor two same values.

  3. In python, a dictionary can have two same values with different keys

  4. In python, a dictionary can have two same keys or same values but cannot have two same key-value pair

  5. Answer:

    In python, a dictionary can have two same values with different keys

    Solution not available.