Predict Set Operations
Predict Output Medium
Question
What does this code print?
Code
a = {1, 2, 3}
b = {3, 4, 5}
print(a | b)
print(a & b)
Hint
| is union, & is intersection.
Explanation
a | b is the union: all elements from both sets = {1, 2, 3, 4, 5}. a & b is the intersection: elements in both = {3}. Output: {1, 2, 3, 4, 5} then {3}.
Related Resources
Related Lessons
- Sets
Set operations.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.