You can empty a dictionary in Python by using the clear()
method. This method removes all the key-value pairs from the dictionary, leaving it empty. Here's an example:
main.py111 chars5 lines
In this example, we define a dictionary my_dict
with three key-value pairs. We then call the clear()
method on this dictionary, which removes all the key-value pairs. Finally, we print the dictionary to verify that it's empty now.
gistlibby LogSnag