What is symmetric_difference() method in sets | How to use symmetric_difference() method of sets?

Definition:

This method is used to return items that are left behind after the intersection of two sets. This method returns the item into the third variable.

sym_diff

Syntax

Variable = A.symmetric_difference(B).

This method takes an argument.

Working:

What is symmetric_difference() 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() method is being applied on set A with set B.
  4. Output is printed into C variable

Output

  1. Output is elements that are left after the intersection of two sets.

Interview Questions

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

The difference() method returns an item that is only present in the first set and not the second, whereas the symmetric_difference method returns an item that is not present in both sets.

Quick Links:

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 *