Python Glossary Русский

all Python 3Sets (set)function

set.clear

modification

Remove all elements, leaving an empty set (in place).

Syntax

s.clear()

clear() empties the object itself, so every name bound to that set sees it become empty. Rebinding a name to a fresh empty set instead changes only that one name and leaves other references pointing at the old data. Calling it on an already empty set is harmless.

Examples

s = {1, 2, 3}
s.clear()
print(s)   # → set()

See also

Open in the full glossarydocs.python.orgReport an inaccuracy