200-901 Software Development and Design Practice Question
A developer is writing a Python script to iterate over a list of server hostnames. Which loop structure is most appropriate to process each hostname in the list?
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
for hostname in hostnames: print(hostname)
The 'for item in list' loop iterates directly over each element, making it the simplest and most readable for processing each hostname.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
for i, hostname in enumerate(hostnames): print(hostname)
Why it's wrong here
The `enumerate()` function returns both an index and the element, but the stem requires only processing each hostname, not tracking its position. The extra index variable `i` is unnecessary overhead for simple iteration. This structure is tempting because `enumerate()` is the correct choice when the loop body needs the index for operations like modifying the list in-place or correlating with a parallel list.
- ✗
while len(hostnames) > 0: print(hostnames.pop())
Why it's wrong here
Destructive and inefficient; modifies the list.
- ✗
for i in range(len(hostnames)): print(hostnames[i])
Why it's wrong here
While functional, it is less Pythonic and requires indexing.
- ✓
for hostname in hostnames: print(hostname)
Why this is correct
Directly iterates over each hostname, which is the recommended approach.
Go deeper
Related to this question
About these practice questions
One of 989 original 200-901 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 200-901 practice question is part of Courseiva's free Cisco certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 200-901 exam.