2. What is the output of the following code?
a={1:"A",2:"B",3:"C"}
b=a.copy()
b[2]="D"
print(a)
Correct Answer is : {1: ‘A’, 2: ‘B’, 3: ‘C’}
3. What is the output of the following code?
a={1:"A",2:"B",3:"C"}
a.clear()
print(a)
Correct Answer is : { }
4. Which of the following isn’t true about dictionary keys?
Correct Answer is : Keys must be integers
5. What is the output of the following code?
a={1:5,2:3,3:4}
a.pop(3)
print(a)
Correct Answer is : {1: 5, 2: 3}
6. What is the output of the following code?
a={1:5,2:3,3:4}
print(a.pop(4,9))
Correct Answer is : 9
7. What is the output of the following code?
a={1:"A",2:"B",3:"C"}
for i in a:
print(i,end=" ")
Correct Answer is : 37623
8. Execute the following in Python shell?
>>> a={1:"A",2:"B",3:"C"}
>>> a.items()
Correct Answer is : dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])
9. Which of the statements about dictionary values if false?
Correct Answer is : Values of a dictionary must be unique
10. What is the output of the following snippet of code?
>>> a={1:"A",2:"B",3:"C"}
>>> del a
Correct Answer is : del deletes the entire dictionary
11. If a is a dictionary with some key-value pairs, what does a.popitem() do?
Correct Answer is : Removes an arbitrary element
12. What is the output of the following snippet of code?
total={}
def insert(items):
if items in total:
total[items] += 1
else:
total[items] = 1
insert('Apple')
insert('Ball')
insert('Apple')
print (len(total))
Correct Answer is : 2
13. What is the output of the following snippet of code?
a = {}
a[1] = 1
a['1'] = 2
a[1]=a[1]+1
count = 0
for i in a:
count += a[i]
print(count)
Correct Answer is : 4
14. What is the output of the following snippet of code?
numbers = {}
letters = {}
comb = {}
numbers[1] = 56
numbers[3] = 7
letters[4] = 'B'
comb['Numbers'] = numbers
comb['Letters'] = letters
print(comb)