Report Bug

Qus

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

 a = {}
a[1] = 1
a['1'] = 2
a[1.0]=4
count = 0
for i in a:
    count += a[i]
print(count)
print(a)
Qus

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

 a = {}
a[1] = 1
a['1'] = 2
a[1.0]=4
count = 0
for i in a:
    count += a[i]
print(count)
print(a)


A. An exception is thrown
B. 3
C. 6
D. 2


Solution
C. 6



Explanation
The value of key 1 is 4 since 1 and 1.0 are the same. Then, the function count() gives the sum of all the values of the keys (2+4).
CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad