⊗pyPmStAERe 116 of 208 menu

Removing All Elements from a Set in Python

You can remove all elements from a set using the clear method. You don't need to pass anything to its parameter.

Let us have a set:

st = {'a', 'b', 'c'}

Let's clear it of all elements:

st.clear() print(st) # set()

Given a set:

st = {1, 2, 3, 4, 5}

Clean it up.

Make an empty set and then add three elements to it.

byenru