Dictionary in Python MCQs Exercise I


Ques 1 Dictionary


Dictionary is a.......
  a) Mutable Datatype.
  b) Immutable Datatype.
  c) Both (a) and (b)
  d) None of the above.


b is the correct option





Ques 2 Dictionary


What is the output of the following Python Code?


di={1:1,2:2,4:4}
print(di)

  a) Error
  b) {1:1,2:2,4:4}
  c) We can't print directly.
  d) None of the above.


b is the correct option





Ques 3 Dictionary


What is the output of the following Python Code?


di={1:1,2:4,4:16}
print(di[2])

  a) 1
  b) 4
  c) 16
  d) 4:16


b is the correct option

The given Python code creates a dictionary di with the key-value pairs {1:1, 2:4, 4:16}. It then prints the value corresponding with the key 2.
The value associated with the key 2 in the dictionary is 4.
So the correct answer is b) 4





Ques 4 Dictionary


What is the output of the following Python Code?


d1={1:1,2:4,4:16}
d2={-1:1,-2:4,-3:6}
if d1>d2:
    print("YES")
else:
    print("No")

  a) YES
  b) NO
  c) Error
  d) None of these


c is the correct option

The given Python code will gives an error because dictionary comparison using the > operator is not supported in Python. Comparing dictionaries directly using comparison operators like >, <, >=, and <= is not allowed, and it will raise a TypeError.
So the correct answer is c)Error