Question:

Consider the statements given below and then choose the correct output from the given options:
D = {'S01': 95, 'S02': 96}
for I in D:
    print(I, end='#')

Show Hint

By default, iterating over a dictionary yields its keys.
Use D.values() to get values and D.items() to get key-value pairs.
  • S01#S02#
  • 95#96#
  • S01,95#S02,96#
  • S01#95#S02#96#
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

In this question, a dictionary D is defined with keys `'S01'` and `'S02'` and values 95 and 96 respectively.
The for loop iterates over D.
When a for loop iterates over a dictionary in Python, it iterates over the keys by default.
So, I takes the value `'S01'` first, then `'S02'`.
Inside the loop, the print() function prints the key and adds `#` at the end without moving to a new line.
Therefore, the output will be `S01#S02#`.
It will not print the values 95 and 96 because only the keys are accessed in the loop.
So, option (A) is the correct answer.
Was this answer helpful?
0
0

Top Questions on Programming in Python

View More Questions

Questions Asked in CBSE CLASS XII exam

View More Questions