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.

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.

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

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

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