Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:57:28+00:00 2026-06-15T22:57:28+00:00

Python sets have these methods: s.union(t) s | t new set with elements from

  • 0

Python sets have these methods:

s.union(t)  s | t   new set with elements from both s and t

s.update(t) s |= t  return set s with elements added from t

Likewise, there’s also these:

s.intersection_update(t)    s &= t  return set s keeping only elements also found in t

s.intersection(t)   s & t   new set with elements common to s and t

And so on, for all the standard relational algebra operations.

What exactly is the difference here? I see that it says that the update() versions returns s instead of a new set, but if I write x = s.update(t), does that means that id(x) == id(s)? Are they references to the same object now?

Why are both sets of methods implemented? It doesn’t seem to add any significant functionality.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:57:30+00:00Added an answer on June 15, 2026 at 10:57 pm

    They are very different. One set changes the set in place, while the other leaves the original set alone, and returns a copy instead.

    >>> s = {1, 2, 3}
    >>> news = s | {4}
    >>> s
    set([1, 2, 3])
    >>> news
    set([1, 2, 3, 4])
    

    Note how s has remained unchanged.

    >>> s.update({4})
    >>> s
    set([1, 2, 3, 4])
    

    Now I’ve changed s itself. Note also that .update() didn’t appear to return anything; it did not return s to the caller and the Python interpreter did not echo a value.

    Methods that change objects in-place never return the original in Python. Their return value is always None instead (which is never echoed).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Python 2.6, with the set() builtin, not sets.set. I have defined some custom
I have two sets of numbers, each in a list in my Python script.
I have a simple Python script set up to send Characters to a device
Working in Python, given a list of N sets of integers from the range
I really new to Python and coding in general, but I have been making
I have a python program that calls a stored procedure from db2 database. I
If I have a function that can operate on both sets and lists and
I want to use some features of python like as Tuples and Sets in
I've inherited some python code that contains a rather cryptic decorator. This decorator sets
when I use MySQLdb get this message: /var/lib/python-support/python2.6/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.