Set Methods
clear()
Remove all elements from the set.
set.clear()
set.clear() removes every element from the set in place, leaving an empty set.
Result
Returns
None, the set is cleared in place.
Run it
Try it
Run it and change it
active_users = {"user_1", "user_2", "user_3"}
active_users.clear()
print("Contents:", active_users)
print("Length:", len(active_users)) Output
Press Run to see what it prints.Worth knowing
- Empty set representation: An empty set is displayed as
set()because{}represents an empty dictionary.