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

Definition:

This method returns a union of two set, meaning it returns all the items from both the set excepted duplicate items. The original set remains unchanged.

union

Syntax:

Variable = A.union(B)

This method takes single argument.

Working:

How to use union() method of sets

What is union() method in sets

Code:

  1. Set A is being taken with some random variables.
  2. Set B is being taken with some random variables.
  3. union() method is being applied on set A with set B.
  4. Value is printed in C variable.

Output:

  1. The union of both the sets is printed.

Interview Questions:

  • How to print all the values of set? How to print all the values of sets in a single variable?

To print all the items of sets all at once we will use union() method.

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 *