Python Set issubset() Method
Returns True
if the source set is contained in the other set.
Syntax
Python
Copy Code
set.issubset(otherSet)
Parameters
Parameter | Description |
---|---|
otherSet |
Required. The set to compare with the current set |
Example
Python
Copy Code
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