PCEP-30-02 Exam QuestionsBrowse all questions from this exam

PCEP-30-02 Exam - Question 23


How would you remove all the items from the d dictionary?

Expected output:

Code:

Show Answer
Correct Answer:

Discussion

4 comments
Sign in to comment
hovnivalOption: D
Dec 22, 2024

The correct option to remove all items from the dictionary d and result in an empty dictionary {} is: D. d.clear() Explanation: d.clear() removes all items from the dictionary without deleting the dictionary itself. Other options: d.del() and d.remove() are invalid as these methods do not exist for dictionaries. del d deletes the dictionary entirely, resulting in d no longer being defined. Example: d = {'A': 1, 'B': 2, 'C': 3} d.clear() print(d) # Output: {}

KevinPerdomoOption: D
Mar 4, 2025

Only .clear is a valid method for dictionaries. D is correct

christostz03
Aug 20, 2024

d is the correct answer

OgtMarcOption: D
Apr 15, 2025

d.clear removes all