set() — Python Technical Interview Questions & Answers
set()
set()
- set() is built into Python. You do not import it. Freshers only need one honest call and the printed result — not a long definition.
- set() — output: {1, 2, 3}. Duplicates gone.
- Wrong type often raises TypeError. Empty values matter for bool/all/any. Don’t mix set up with a similar name (sorted vs sort, int vs float).
{1, 2, 2, 3}
│ unique
▼
{1, 2, 3}Technical Interview Tip: Call set() once and say what prints.
Code Examples for set()
Example
# set()
print(set([1, 2, 2, 3]))
set() — output: {1, 2, 3}. Duplicates gone.
How to Explain set() to an Interviewer
Explain set() as if you are teaching a junior — definition, then one tiny script.
set() is built-in — no import. One call + exact output.
What does the example print, and why?
set() — output: {1, 2, 3}
What mistake do freshers make with set()?
Wrong type → TypeError.