Loading

Quipoin Menu

Learn • Practice • Grow

Direction: Choose the correct option

Q1.

What is a dictionary in Python?
A. A set of unique elements
B. An ordered sequence
C. A list of tuples
D. A collection of key-value pairs
Direction: Choose the correct option

Q2.

How do you create an empty dictionary?
A. dict()
B. {}
C. []
D. Both A and B
Direction: Choose the correct option

Q3.

What is the output of `{'a':1, 'b':2}['a']`?
A. 2
B. 1
C. Error
D. 'a'
Direction: Choose the correct option

Q4.

How do you add a new key-value pair to a dictionary `d`?
A. d.update({'new': value})
B. Both A and C
C. d.add('new', value)
D. d['new'] = value
Direction: Choose the correct option

Q5.

What does `d.get('key', default)` do?
A. Returns the key
B. Deletes the key
C. Raises error
D. Returns the value for key if exists, else default
Direction: Choose the correct option

Q6.

How do you remove a key from a dictionary?
A. d.remove('key')
B. del d['key']
C. Both A and B
D. d.pop('key')
Direction: Choose the correct option

Q7.

What is the output of `{'a':1, 'b':2}.keys()`?
A. ('a','b')
B. {'a','b'}
C. dict_keys(['a','b'])
D. ['a','b']
Direction: Choose the correct option

Q8.

Can a dictionary have duplicate keys?
A. Keys are automatically made unique
B. No, keys must be unique
C. Yes, with different values
D. Only if values are different
Direction: Choose the correct option

Q9.

Which of the following can be a dictionary key?
A. set
B. list
C. dict
D. tuple
Direction: Choose the correct option

Q10.

What does `d = {}.fromkeys(['a','b'], 0)` create?
A. {'a':0, 'b':0}
B. {'a':0, 'b':0}
C. {'a':0, 'b':0}
D. {'a':0, 'b':0}