isdisjoint(): checking if two Sets are disjoint in Python

The isdisjoint() method checks for items that exist in both sets.

If one or more items exist in both sets, the method returns False, otherwise it returns True, which means the Sets are disjoint.

car_brands_set_one and car_brands_set_two have ‘bmw’ in common, so isdisjoint() returns False.

car_brands_set_one and car_brands_set_three don’t have any items in common, so isdisjoint() returns True.

car_brands_set_one = {'bmw', 'mclaren', 'ferrari'}

car_brands_set_two = {'honda', 'bmw', 'ford'}

car_brands_set_three = {'honda', 'suzuki', 'ford'}

print(car_brands_set_one.isdisjoint(car_brands_set_two))

print(car_brands_set_one.isdisjoint(car_brands_set_three))
False
True

To learn more about Sets, read this post Python Set: a quick reference