Skip to content
Question 27 of 97

Q.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='#')  
(A) S01#S02# (B) 95#96# (C) S01,95#S02,96# (D) S01#95#S02#96#

Tamil Nadu DgeCBSE Class XII Board 2025MCQ· 1mImportance★★★★★
28% · 27/97 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

When a for loop iterates directly over a Python dictionary, it processes the dictionary's keys. The print() function with end='#' will output each key followed by a hash symbol, resulting in S01#S02#.

A Python dictionary stores data as key-value pairs. Understanding how to iterate over these structures is fundamental. When you use a for loop directly on a dictionary, Python has a specific default behavior: it iterates over the keys of the dictionary. The loop variable will sequentially take on each key.

Additionally, the print() function in Python, by default, adds a newline character (\n) after whatever it prints. However, you can modify this behavior using the end parameter. If you set end='#', then instead of a newline, a hash symbol (#) will be appended after each item printed.

Let's break down the execution step-by-step.

  1. Dictionary Initialization:

    The code begins by defining a dictionary D:

    D = {'S01':95, 'S02':96}

    This dictionary contains two key-value pairs:

    • The key 'S01' is associated with the value 95.
    • The key 'S02' is associated with the value 96.
  2. Looping through the Dictionary:

    Next, a for loop is initiated: for I in D:.

    As discussed, when you iterate directly over a dictionary D, the loop variable I will take on the keys of the dictionary, one by one.

  3. First Iteration:

    In the first pass of the loop, I is assigned the first key from D, which is 'S01'.

    The statement inside the loop is print(I, end='#').

    This command prints the current value of I (which is 'S01') and then appends the character specified by end, which is '#'.

    The output generated at this point is S01#.

  4. Second Iteration: …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.