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.
Returns
None — the set is cleared in place.
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))Worth knowing
- Empty set representation: An empty set is displayed as
set()because{}represents an empty dictionary.