Computer >> Computer tutorials >  >> Programming >> Python

Internal working of Set in Python


In this article, we will learn about the Internal working of Set in Python. We will observe the union and intersection operation in different frames and objects.

Let’s declare an empty set.

>>> s=set()

Internal working of Set in Python

Now let’s declare a set with elements.

>>> s1=set('tutorialspoint')

Internal working of Set in Python

Adding an element into an empty set.

>>> s.add(‘p’)

Internal working of Set in Python

Now we declare another set with the name of Python.

>>> s2=set('python')

Internal working of Set in Python

Now let’s see the union operation.

>>> s3=s1.union(s2)

Internal working of Set in Python

Finally, we implement the intersection option.

>>> s4=s1.intersection(s2)

Internal working of Set in Python

Conclusion

In this article, we learned about the Internal working of Set in Python 3.x. Or earlier