0
0
Pythonprogramming~5 mins

Union and intersection in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the union of two sets in Python?
The union of two sets is a new set containing all unique elements from both sets. It combines elements without duplicates.
Click to reveal answer
beginner
What does the intersection of two sets represent?
The intersection of two sets is a new set containing only the elements that appear in both sets.
Click to reveal answer
beginner
How do you find the union of sets a and b in Python?
You can use a.union(b) or the | operator like a | b.
Click to reveal answer
beginner
How do you find the intersection of sets a and b in Python?
You can use a.intersection(b) or the & operator like a & b.
Click to reveal answer
beginner
If a = {1, 2, 3} and b = {3, 4, 5}, what is a | b and a & b?
a | b is {1, 2, 3, 4, 5} (union), and a & b is {3} (intersection).
Click to reveal answer
Which operator gives the union of two sets a and b in Python?
A|
B&
C^
D-
What does a & b return when a and b are sets?
AIntersection of a and b
BDifference of a and b
CUnion of a and b
DSymmetric difference of a and b
Which method can be used to find the union of two sets a and b?
Aa.intersection(b)
Ba.difference(b)
Ca.union(b)
Da.symmetric_difference(b)
If a = {1, 2} and b = {2, 3}, what is a & b?
A{1, 2, 3}
B{1}
Cset()
D{2}
What will a | b return if a = {5, 6} and b = {6, 7}?
A{6}
B{5, 6, 7}
C{5, 7}
D{}
Explain in your own words what the union and intersection of two sets mean.
Think about combining two groups of friends versus finding friends you both have.
You got /2 concepts.
    Describe how to find the union and intersection of two sets in Python using operators and methods.
    Remember the symbols look like OR and AND.
    You got /4 concepts.