What is the difference_update method in sets in python | How to use the difference_update method of sets?

Definition:

This method is used to remove common items from set A, given that A.difference_update(B). All changes are done in the original set only no 3rd variable is involved in this method. Simply put, all it does is

A=A-B | All the operation done is stored in A itself.

difference

Syntax:

A.difference_update(B)

All changes are done in the original set itself.

This method takes an argument

Working:

What is the difference_update method in sets

output

Code:

  1. A set is taken
  2. B set is taken
  3. difference_update() method is applied on set A using B
  4. Value of set A is printed

Output:

  1. A set is printed excluding common item from set B.

Interview Questions:

  • What is difference between difference method and update difference method?

Difference method apply changes and result is stored in another variable, whereas in difference update method applied changes is stored in original set itself.

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 *