GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Python Set difference() - GeeksforGeeks Python Set difference()Last Updated : 18 Apr, 2026 The set.difference() method in Python returns a new set containing elements that are present in the first set but not in the other given set(s). It performs set subtraction and removes all common elements. The original sets remain unchanged. ![]() Example: In this example, elements that are present in one set but not in another are found using difference().
Output {10, 20}
{100, 60}
Explanation:
Syntax
ExamplesExample 1: In this example, the difference is calculated using multiple sets.
Output {1, 2}
Explanation: a.difference(b, c) removes elements found in b or c, only elements unique to a remain. Example 2: Here, the difference of a set with an empty set is demonstrated.
Output {40, 10, 20, 30}
Explanation: a.difference(b) removes elements of b from a. Since b is empty, a remains unchanged. Example 3: In this example, the difference operation is performed when one set is a subset of another.
Output set() Explanation:
Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |