Python Set issubset() Method

Returns True if the source set is contained in the other set.

Syntax

Python
set.issubset(otherSet)

Parameters

ParameterDescription
otherSet Required. The set to compare with the current set

Example

Python
desktopComponents = {'memory', 'processor'}
laptopComponents = {'memory', 'processor', 'SSD', 'camera', 'keyboard'}

desktopIsSubset = desktopComponents.issubset(laptopComponents)
laptopIsSubset = laptopComponents.issubset(desktopComponents)

print(f'Desktop computer components are a subset of a laptop computer components: {desktopIsSubset}')
print(f'Laptop computer components are a subset of a desktop computer components: {laptopIsSubset}')

Output

Desktop computer components are a subset of a laptop computer components: True
Laptop computer components are a subset of a desktop computer components: False