CBSE Class 12 Computer Science
Question 37 of 44
Solved 2025 Sample Question Paper CBSE Class 12 Computer Science (083) — Question 5
Back to all questions15@
7@
9@
Initialization:
- A dictionary
dis created with three key-value pairs. - An empty string
str1is initialized.
Iteration:The
forloop iterates over each key in the dictionary:
- For "apple":
str1becomes "15@\n" (value 15 followed by "@" and a newline). - For "banana":
str1becomes "15@\n7@\n" (adding value 7 followed by "@" and a newline). - For "cherry":
str1becomes "15@\n7@\n9@\n" (adding value 9 followed by "@" and a newline).
The line
str2 = str1[:-1]removes the last newline character fromstr1, resulting instr2being "15@\n7@\n9@".Finally,
print(str2)outputs the content ofstr2.