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()

Now let’s declare a set with elements.

>>> s1=set('tutorialspoint')

Adding an element into an empty set.

>>> s.add(‘p’)

Now we declare another set with the name of Python.

>>> s2=set('python')

Now let’s see the union operation.

>>> s3=s1.union(s2)

Finally, we implement the intersection option.

>>> s4=s1.intersection(s2)

Conclusion

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

Updated on: 2019-08-29T11:43:38+05:30

413 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements