Computer Science
Which of the following will raise an error if the given key is not found in the dictionary ?
- del statement
- pop( )
- popitem()
- all of these
Python Dictionaries
1 Like
Answer
del statement
Reason — For example:
d = {'list': 'mutable', 'tuple': 'immutable'}
del d['dictionary']
Output
<module> KeyError: 'dictionary'
Since key named "dictionary" does not exist in d, del keyword will raise an error.
Answered By
1 Like
Related Questions
Which value is assigned to keys, if no value is specified with the fromkeys() method ?
- 0
- 1
- None
- any of these
Which of the following can be used to delete item(s) from a dictionary?
- del statement
- pop( )
- popitem( )
- all of these
Which of the following will raise an error if the given dictionary is empty ?
- del statement
- pop( )
- popitem( )
- all of these
A copy of the dictionary where only the copy of the keys is created for the new dictionary, is called …………… copy.
- key copy
- shallow copy
- deep copy
- partial copy