Content · Programming · Python

Python set.update Method: Usage and Examples

set.update(*others) adds all elements from one or more iterables into an existing set. Unlike add(), it consumes the iterables and inserts their individual elements. See two practical examples, edge cases and common.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

A permission set receives multiple new capabilities at once.

What You Need to Understand


set.update(*others) adds all elements from one or more iterables into an existing set. Unlike add(), it consumes the iterables and inserts their individual elements.

When to Use It


A permission set receives multiple new capabilities at once.

Step-by-Step Python Example


permissions = {"read"}
result = permissions.update(["write", "export"], {"admin"})
print(sorted(permissions))
print(result)

How the Example Works


All three new strings are added and result is None, because the set was mutated.

Example Output


['admin', 'export', 'read', 'write']
None
[1, 2, 3]

A Second Example


Compare this smaller variation with the main example, then experiment with your own values.

items = {1}
items.update((2, 3))
print(sorted(items))

Important Behavior and Edge Cases


update("abc") inserts the individual characters, not the complete string. Use add("abc") to add one string member.

Try It Yourself


Update a set with a tuple of numeric IDs.

Common Beginner Mistakes


  • update("abc") inserts the individual characters, not the complete string. Use add("abc") to add one string member.
  • Using the wrong collection method for this operation without checking whether it mutates the object, returns a result, or raises on missing data.

Key Takeaways


  • set.update(*others) adds all elements from one or more iterables into an existing set.
  • All three new strings are added and result is None, because the set was mutated.
  • update("abc") inserts the individual characters, not the complete string.
Share this resourceSend this page to someone who may find it useful.