Write a Python Program to Illustrate Different Set Operations

Python Program to Illustrate Different Set Operations

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn  Python programming concepts. You can learn Python language at your own speed and time. One can learn concepts of Python language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Python Program to Illustrate Different Set Operations
Python Program to Illustrate Different Set Operations

Write a Python Program to Illustrate Different Set Operations

PROGRAM: Python Program to Illustrate Different Set Operations

/* Python Program to Illustrate Different Set Operations */

# Program to perform different set operations like in mathematics

# define three sets
E = {0, 2, 4, 6, 8};
N = {1, 2, 3, 4, 5};

# set union
print(“Union of E and N is”,E | N)

# set intersection
print(“Intersection of E and N is”,E & N)

# set difference
print(“Difference of E and N is”,E – N)

# set symmetric difference
print(“Symmetric difference of E and N is”,E ^ N)

Output:

Union of E and N is {0, 1, 2, 3, 4, 5, 6, 8}
Intersection of E and N is {2, 4}
Difference of E and N is {8, 0, 6}
Symmetric difference of E and N is {0, 1, 3, 5, 6, 8}
 

		

Leave a Reply

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