Coders Packet

Powerset of a Set using Python programming language

By Shaik Jilani

Write a Program to determine the Powerset of a Set using the Python programming language.


Set is defined as the collection of distinct elements.

A set may contain different elements like alphabets, numbers, people, geometrical shapes, etc.

In a set, elements are written in the curly braces { }.

Eg: A = {3,5,7,8,123}


Powerset is defined as the set of all subsets of a set. Subsets includes emptyset and itself.

let the set be A then its powerset is denote as P(A).


set A={4,5,6}

subsets of set A are {},{4},{5},{6},{4,5},{4,6},{5,6},{4,5,6}

Powerset of set A=P(A)={{},{4},{5},{6},{4,5},{4,6},{5,6},{4,5,6}}

Explanation of code:

 In this program, we consider a set as an input. The powerset of the set is an empty set if the input set is the empty set.

If the input set is not empty, then we use the 'for' loop. In that loop, we use the append function to get different Sets. The combination of all the sets obtained from the append function is the powerset of the input set.

Download Complete Code


No comments yet