Set Methods0%

Set Methods

Beginner8 min readUpdated: 2026-09-03
Study Materials

Set Methods

Test subset, superset, and disjoint relationships between sets.


Key Concepts & Detailed Explanation

undefined


Code Examples & Output

Python
full_curriculum = {"Python", "HTML", "CSS", "JS", "SQL", "Git"}
student_skills = {"Python", "HTML", "CSS"}
unrelated_skills = {"Cooking", "Painting"}
 
print("Is student a subset?", student_skills.issubset(full_curriculum)) # True
print("Is curriculum superset?", full_curriculum.issuperset(student_skills)) # True
print("Are unrelated skills disjoint?", student_skills.isdisjoint(unrelated_skills)) # True

Expected Output:

Output
Is student a subset? True
Is curriculum superset? True
Are unrelated skills disjoint? True

Best Practices & Common Pitfalls

isdisjoint() returns True if two sets share zero elements in common.


Practice Quiz

1. What does 'set1.isdisjoint(set2)' return if they have no common elements?

  • A) False
  • B) True
  • C) None
  • D) Error
Answer: B Explanation: isdisjoint() returns True when the intersection is empty.

2. If every element of A is also in B, what does A.issubset(B) return?

  • A) True
  • B) False
  • C) None
  • D) Equal
Answer: A Explanation: A is a subset of B if all its items exist in B.

Practice Challenge

Verify whether a candidate's submitted skills are a complete subset of the job prerequisites.

Next Lesson

Nested Sets

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Set OperationsNested Sets

Practice Quiz

Test your understanding of this lesson with 1 questions. Each question has one correct answer.

PrevNext