>>> s = {'Alice', 'Bob'} >>> t = {'Alice', 'Bob', 'Carl', 'Liz'} >>> s.issubset(t) True

Another minimal Harry Potter example:

>>> hogwarts = {'Ron', 'Harry', 'Hermione', 'Dumbledore', 'Parvati', 'Malfoy'} >>> gryffindors = {'Ron', 'Harry', 'Hermione'} >>> gryffindors.issubset(hogwarts) True

## Syntax

set.issubset(set)

## Return Value of set.issubset()

## Advanced Examples set.issubset()

We start with a simple and trivial example:

>>> {'Alice'}.issubset({'Alice', 'Bob'}) True

? Can you also pass a list as an argument to the `set.issubset()`

method? The answer is yes—the method takes any iterable.

>>> {'Alice'}.issubset(['Alice', 'Bob']) True

A set is the subset of itself.

>>> s = {1, 2, 3} >>> s.issubset(s) True

This also means that two empty sets are the subsets of each other.

>>> set().issubset(set()) True

In fact, the empty set is a subset of every other set.

>>> set().issubset({1, 2, 3}) True

Can we pass multiple set arguments into the `set.issubset()`

method? No! It only takes one argument.

>>> {1, 2, 3}.issubset({1, 2}, {3}) Traceback (most recent call last): File "<pyshell#18>", line 1, in <module> {1, 2, 3}.issubset({1, 2}, {3}) TypeError: issubset() takes exactly one argument (2 given)

To fix this `TypeError`

, pass only one set argument into the `set.issubset()`

method.

## What is the Time Complexity of set.issubset() in Python?

import matplotlib.pyplot as plt import time sizes = [i * 10**5 for i in range(50)] runtimes = [] for size in sizes: t = set(range(size)) s = set(range(0, size, 2)) # Start track time ... t1 = time.time() s.issubset(t) t2 = time.time() # ... end track time runtimes.append(t2-t1) plt.plot(sizes, runtimes) plt.ylabel('Runtime (s)') plt.xlabel('Set Size') plt.show()

## Other Python Set Methods

While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.

To help students reach higher levels of Python success, he founded the programming education website Finxter.com that has taught exponential skills to millions of coders worldwide. He’s the author of the best-selling programming books Python One-Liners (NoStarch 2020), The Art of Clean Code (NoStarch 2022), and The Book of Dash (NoStarch 2022). Chris also coauthored the Coffee Break Python series of self-published books. He’s a computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.

His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.