Table of Contents
Definition:
This method is used to return another set which is in A and not in B, meaning, A – B is applied and whatever remains in A will be passed into another variable. Also, the original set remains the unchanged.
Syntax:
Variable = set1.difference(set2)
This method takes an argument.
Working:
Code:
- A set with some values is taken
- Another set with some common values in set A is taken.
- difference() method on set A is applied with B and that value is passed to C.
- The value of C is printed
Output:
- A set with A-B is printed where we cannot see common items of A & B.
Interview Questions:
- How to remove common items from first set and don’t want to print the data in 3rd variable, we want changes in original set itself.
To achieve this kind of changes there is a method called difference_update().
Quick Topics:
How to reverse a string in python using for loop?
In this article we will see how to reverse a string in python using for loop also we will different ways in which we can store the output, example the output can be stored in the string itself or maybe a list or maybe a tuple. We highly encourage you to read our …
How to reverse a string in python using for loop?Read More »
What Are List/Array Methods | Types Of Methods In Python List.
Python list methods. 1. append( ) This method is used to append or say insert an element into the existing list. It takes only one value as an argument. Code: Output: The new value is always inserted at the end of the list. Also, we can pass iterative objects into list or say list into …
What Are List/Array Methods | Types Of Methods In Python List.Read More »
What is a list in python, How to use list and its methods?
What is a List In Python? The list is used to storing multiple or different types of data be it integer, character or floating-point in a single variable. The list is one of 4 collection data types. List stores data in the indexed form and it is mutable, that is we can change the stored …
What is a list in python, How to use list and its methods?Read More »
Different types of collection data types in python.
In python, we have several data types like any other programming language, including integer, float, char, String, Boolean, etc. But as we all know python is the fastest growing language in the world and it has many reasons, one of which is its collection of data types. As we can assume from the name itself …
Different types of collection data types in python.Read More »