w3resource logo


Python Exercises

Python Exercise: Intersection of sets

Python sets: Exercise-6 with Solution

Write a Python program to create an intersection of sets.

Sample Solution :-

Python Code :

#Intersection
setx = set(["green", "blue"])
sety = set(["blue", "yellow"])
setz = setx & sety
print(setz)

Output :

{'blue'}

Python Code Editor:

#Intersection
setx = set(["green", "blue"])
sety = set(["blue", "yellow"])
setz = setx & sety
print(setz)

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Solve these problems:

Java: How to convert a string to an integer in Java?

C#: Loops in c#

SQL: JOIN using more than 5 tables