Python Set isdisjoint() Method
Returns True
if the two sets do not have any items in common. Returns False
if the
two sets have an item in common (the two sets have an intersection).
Syntax
Python
Copy Code
set.isdisjoint(otherSet)
Parameters
Parameter | Description |
---|---|
otherSet |
Required. The set to compare with the current set |
Example
Python
Copy Code
desktopComponents = {'memory', 'processor', 'hard drive'} laptopComponents = {'memory', 'processor', 'SSD', 'camera', 'keyboard'} inCommon = laptopComponents.isdisjoint(desktopComponents) print(f'Desktop and laptop computers do NOT have components in common: {inCommon}') desktopComponents = {'memory', 'processor', 'hard drive'} mouseComponents = {'wheel', 'button', 'laser'} inCommon = desktopComponents.isdisjoint(mouseComponents) print(f'Desktop computers and optical mice do NOT have components in common: {inCommon}')
Output
Desktop and laptop computers do NOT have components in common: False Desktop computers and optical mice do NOT have components in common: True