VOOZH about

URL: https://www.geeksforgeeks.org/python/intersection-function-python/

⇱ Intersection() function Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Intersection() function Python

Last Updated : 18 Apr, 2026

The set.intersection() method in Python returns a new set containing only the elements that are common to all given sets. It compares two or more sets and keeps only shared values. The original sets remain unchanged.

👁 420851442
Intersection of two sets

Example: In this example, common elements between two sets are found using intersection().


Output
{2, 3}

Explanation: a.intersection(b) returns elements present in both sets, only 2 and 3 are common.

Syntax

set1.intersection(set2, set3, ...)

  • Parameters: One or more sets to compare. If no argument is given, it returns a copy of the original set.
  • Return Value: Returns a new set containing common elements.

Examples

Example 1: In this example, the intersection of two and three sets is calculated.


Output
{4, 6}
{4, 6}

Explanation:

  • a.intersection(b) returns common elements of a and b.
  • a.intersection(b, c) returns elements common to all three sets.

Example 2: Here, the & operator is used as a shortcut for intersection.


Output
{4, 6}
set()
set()

Explanation:

  • a & b returns common elements of both sets.
  • a & c returns set() because no elements match.
  • a & b & c returns common elements among all three sets.

Example 3: In this example, intersection() is compared with symmetric_difference().


Output
{4, 6}
{2, 5, 7, 8}

Explanation:

  • a.intersection(b) returns common elements.
  • a.symmetric_difference(b) returns elements not common in both sets.
  • Intersection keeps shared values, while symmetric difference keeps non-shared values.
Comment