Set Methods

set.pop()

Mutates the original set, so aliases observe the change. Choose and remove one member and return it. The choice is unspecified, not random, sorted, first-in or last-in. Do not depend on the exact member chosen for a multi-element set; verify membership and the remaining contents instead. Raises KeyError when there is no member to remove. A list or deque is more suitable if removal order matters.

Formal Syntax & Structure

python syntaxpython
items.pop()

Return Value

object

The actual member removed.

Working Example

Example Snippetpython
pending = {"build", "test", "ship"}before = pending.copy()removed = pending.pop()print(removed in before)print(removed in pending, len(pending))
Python Reference