What is symmetric_difference_update() method in sets | How to use symmetric_difference_update() method of sets.

Definition:

This method is used to remove the common items from set A and it inserts the unique item from set B. Given that A.symmetric_difference_update(B). Also, this method directly works in original set, therefore original set itself is changed.

What is symmetric_difference_update() method in sets in python

Syntax:

A.symmetric_difference_update(B)

This method takes argument.

Working:

How to use symmetric_difference_update() method of sets

What is symmetric_difference_update() method in sets

Code:

  1. Set A is being taken with some random values.
  2. Set B is being taken with some random values.
  3. symmetric_difference_update() method is being applied on set A with the help of set B.
  4. Value of set A is printed
  5. Value of set B is printed

Output:

  1. Set A has non-common items as well as unique items from set B.
  2. Set B remains unchanged.

Interview Questions:

  • What is the difference between symmetric_difference() and symmetric_difference update() method?

symmetric_difference() method returns non common items from both the sets in another variable, whereas symmetric_difference_update() method alters the original set with non-common items from both the set.

Waqar Khan

Hello, everyone, I am Waqar Khan. I have done my B.tech in Computer Science. I love to write about Computer Informational blogs. Before write I did proper research on it. Hope you like our blogs. Thank you.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *