Python Practice › Set Programs › Program 7

Intersection of two sets

EasySet Programs · 7 of 48

Write a Python program to find the intersection of two sets.

Advertisement
Input
{1, 2, 3, 4}, {3, 4, 5}
Output
{3, 4} {3, 4}

Approach

  1. & or intersection().

Solution

Python
a, b = {1, 2, 3, 4}, {3, 4, 5}print(a & b, a.intersection(b))
Output
{3, 4} {3, 4}
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More set programs

← All 48 Set Programs