Informatics Practices
Find errors and rewrite the same after correcting the following code:
d1.clears()
Python Dictionaries
1 Like
Answer
The correct method to clear all elements from a dictionary is clear(), not clears().
The corrected code is:
d1.clear()
Answered By
3 Likes
Related Questions
Find errors and rewrite the same after correcting the following code:
d1.gets(4, 80)Find errors and rewrite the same after correcting the following code:
d1.len()Suppose
>>> d1 = { 1 : 'one' , 2: 'two' , 3: 'three' , 4: 'four'} >>> d2 = { 5 :'five', 6:'six' }Write the output of the following code:
>>> d1.items() >>> d1.keys() >>> d1.values() >>> d1.update(d2) >>> len(d1)Suppose
>>> d1 = { 1 : 'one' , 2: 'two' , 3: 'three' , 4: 'four'} >>> d2 = { 5 :'five', 6:'six' }Write the output of the following code:
>>> del d1[3] >>> print(d1) >>> d1.pop(4) >>> print(d1) >>> d1 [8] =' eight' >>> print(d1) >>> d1.clear() >>> print(d1)