Question 4:Find the output of the following program:
D = dict() for i in range (3): for j in range(2): D[i] = j print(D) |
chevron_right
filter_none
(A) {0: 0, 1: 0, 2: 0}
(B) {0: 1, 1: 1, 2: 1}
(C) {0: 0, 1: 0, 2: 0, 0: 1, 1: 1, 2: 1}
(D) TypeError: Immutable object
Answer: (B)
Explanation: 1st loop will give 3 values to i 0, 1 and 2. In the empty dictionary, valued are added and overwrited in j loop, for eg. D[0] = [0] becomes D[0] = 1, due to overwriting.
Quiz of this Question
Recommended Posts:
- Python-Quizzes | Python Dictionary Quiz | Question 23
- Python-Quizzes | Python Dictionary Quiz | Question 1
- Python-Quizzes | Python Dictionary Quiz | Question 2
- Python-Quizzes | Python Dictionary Quiz | Question 3
- Python-Quizzes | Python Dictionary Quiz | Question 5
- Python-Quizzes | Python Dictionary Quiz | Question 6
- Python-Quizzes | Python Dictionary Quiz | Question 7
- Python-Quizzes | Python Dictionary Quiz | Question 8
- Python-Quizzes | Python Dictionary Quiz | Question 9
- Python-Quizzes | Python Dictionary Quiz | Question 10
- Python-Quizzes | Python Dictionary Quiz | Question 11
- Python-Quizzes | Python Dictionary Quiz | Question 12
- Python-Quizzes | Python Dictionary Quiz | Question 13
- Python-Quizzes | Python Dictionary Quiz | Question 14
- Python-Quizzes | Python Dictionary Quiz | Question 15
- Python-Quizzes | Python Dictionary Quiz | Question 16
- Python-Quizzes | Python Dictionary Quiz | Question 17
- Python-Quizzes | Python Dictionary Quiz | Question 18
- Python-Quizzes | Python Dictionary Quiz | Question 19
- Python-Quizzes | Python Dictionary Quiz | Question 20

