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
Popping from the list mutates hostnames, destroying the original data and skipping elements if the loop is re-entered; a for loop over the list iterates without side effects. It is tempting because while loops suit unknown iteration counts, and would be correct when consuming a queue until empty.
- ✗
for i in range(len(hostnames)): print(hostnames[i])
Why it's wrong here
Indexing with range(len()) works but is unpythonic and obscures intent; iterating directly over hostnames is the idiomatic structure for processing each element. It is tempting because indices are needed when the position matters, which would make this the correct choice for tasks referencing element numbers.
- ✓
for hostname in hostnames: print(hostname)
Why this is correct
A for loop iterates directly over the hostnames list, binding each element to the loop variable in turn, which is the idiomatic structure for processing every item in a sequence. It satisfies the requirement to process each hostname without manual index management.
Go deeper
Related to this question
About these practice questions
One of 975 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.