Get the App
SLTechnology News&Howtos  ›  Development  › 

How python uses clear () to delete dictionary key-value pairs

Shulou Source: shulou.com Published: 2022-06-01 03:06:00 09月22日 Update

Clear () delete dictionary key-value pair: clear everything in the dictionary, but do not delete the dictionary itself, del delete dictionary itself dict4 = {'name':' Tom', 'age': 18} dict4.clear () print (dict4)

Return: {}

Dict (dictionary) in python:

1. The dictionary is another variable container model, in which each key-value pair is separated by a colon (:), each key-value pair is separated by a comma (,), and the whole dictionary is surrounded by curly braces {}

two。 The key in the dictionary is generally unique. If repeated, the following key-value pair will overwrite the previous one, but the dictionary value does not need to be unique.

3. The value can take any data type, but the key must be an immutable type, such as a string, number, or tuple, but not a list because the list is mutable.

The above is all the content of the article "how python uses clear () to delete dictionary key-value pairs". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Dictionary content article variable type learning help between colon character string container parenthesis number data easy to understand more organization model knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MariaDB Redmi OPPO Reno NVidia