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