MCQ Answer

<p>What will be the output of the following Python code snippet?</p> <pre><font color="#333333">total={}<br></font><font color="#333333">def insert(items):<br></font><font color="#333333">&nbsp; &nbsp; if items in total:<br></font><font color="#333333">&nbsp; &nbsp; &nbsp; &nbsp; total[items] += 1<br></font><font color="#333333">&nbsp; &nbsp; else:<br></font><font color="#333333">&nbsp; &nbsp; &nbsp; &nbsp; total[items] = 1<br></font><font color="#333333">insert('Apple')<br></font><font color="#333333">insert('Ball')<br></font><font color="#333333">insert('Apple')&nbsp;<br></font><font color="#333333">print (len(total))</font></pre><div><br></div>

What will be the output of the following Python code snippet?

total={}
def insert(items):
    if items in total:
        total[items] += 1
    else:
        total[items] = 1
insert('Apple')
insert('Ball')
insert('Apple') 
print (len(total))



निम्नलिखित Python कोड स्निपेट का आउटपुट क्या होगा?

total={}
def insert(items):
    if items in total:
        total[items] += 1
    else:
        total[items] = 1
insert('Apple')
insert('Ball')
insert('Apple') 
print (len(total))
Topic : Sequence data types in python

A. 3

B. 1

C. 2

D. 0




Correct Answer is :

C. 2



Explanation
The insert() function counts the number of occurrences of the item being inserted into the dictionary. There are only 2 keys present since the key ‘Apple’ is repeated. Thus, the length of the dictionary is 2.
Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad