Question 26 of 511
StringshardMultiple ChoiceObjective-mapped

Quick Answer

The answer is to use `line.split()` instead of `line.split(' ')`. This is correct because `line.split()` with no arguments splits on any whitespace—spaces, tabs, or newlines—and automatically discards any empty strings from the result, so `'interface GigabitEthernet0/1'` cleanly becomes `['interface', 'GigabitEthernet0/1']`. In contrast, `line.split(' ')` splits only on a single space character, leaving empty strings when multiple spaces or tabs appear, which breaks parsing of router configuration files. On the PCAP exam, this tests your understanding of Python’s string method defaults and common pitfalls in data parsing; a frequent trap is assuming `split(' ')` and `split()` behave identically. For the Certified Associate Python Programmer exam, remember that `split()` without arguments treats all whitespace as one delimiter and ignores leading/trailing whitespace, making it the robust choice for real-world text like config files. Memory tip: “No argument, no empty fragments”—when you call `split()` bare, it cleans up messy whitespace for you.

PCAP Strings Practice Question

This PCAP practice question tests your understanding of strings. The scenario asks you to isolate a root cause — eliminate options that address a different problem before choosing. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

You are a network engineer troubleshooting a script that processes router configuration files. The script reads a configuration line from a file: 'interface GigabitEthernet0/1

ip address 192.168.1.1 255.255.255.0
 no shutdown'. The script needs to extract the interface name and IP address. The current code uses string split operations but fails when the line has extra spaces or tabs. For example, when the line is 'interface   GigabitEthernet0/1', the split returns ['interface', '', '', 'GigabitEthernet0/1'] and the script fails. You need to modify the script to robustly extract the interface name and IP address regardless of whitespace. Which approach should you take?
Question 1hardmultiple choice
Review the full routing breakdown →

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

Use line.split() instead of line.split(' ').

Option B is correct because `line.split()` without arguments splits on any whitespace (spaces, tabs, newlines) and automatically removes empty strings, making it robust against extra spaces or tabs. In contrast, `line.split(' ')` splits only on single space characters, leaving empty strings when multiple spaces or tabs are present. This behavior is defined by Python's string method documentation and is essential for parsing configuration files where whitespace is inconsistent.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Manually iterate and concatenate characters until a space is found.

    Why it's wrong here

    Reinventing the wheel, error-prone.

  • Use line.split() instead of line.split(' ').

    Why this is correct

    split() with no arguments splits on any whitespace and discards empty strings.

    Related concept

    Read the scenario before looking for a memorised answer.

  • Use line.split(' ') and then filter out empty strings.

    Why it's wrong here

    Works but less efficient than split().

  • Use line.startswith('interface') to identify the line, then extract substring.

    Why it's wrong here

    Does not handle extraction of the interface name properly.

Common exam traps

Common exam trap: answer the scenario, not the keyword

The trap here is that candidates often confuse `split()` with `split(' ')`, assuming they behave identically, but `split(' ')` only splits on a single space character and leaves empty strings for multiple spaces or tabs, while `split()` handles all whitespace and removes empties automatically.

Detailed technical explanation

How to think about this question

Under the hood, `str.split()` with no arguments uses a whitespace-based splitting algorithm that treats any sequence of whitespace characters (spaces, tabs, form feeds, etc.) as a single delimiter, as per Python's string implementation. This is particularly useful when parsing network device configurations (e.g., Cisco IOS) where indentation or tab characters are common. A real-world scenario is parsing a router's running-config where lines like 'interface GigabitEthernet0/1' (with double space) or 'interface\tGigabitEthernet0/1' (with tab) must be handled reliably.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A healthcare organisation deploys an application with a public-facing web tier and a private database tier. The database subnet has no public IP and only accepts connections from the web tier's security group. Questions like this test whether you can design cloud network isolation using VNets/VPCs, subnets, and security group rules.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related PCAP practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free PCAP practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this PCAP question test?

Strings — This question tests Strings — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: Use line.split() instead of line.split(' '). — Option B is correct because `line.split()` without arguments splits on any whitespace (spaces, tabs, newlines) and automatically removes empty strings, making it robust against extra spaces or tabs. In contrast, `line.split(' ')` splits only on single space characters, leaving empty strings when multiple spaces or tabs are present. This behavior is defined by Python's string method documentation and is essential for parsing configuration files where whitespace is inconsistent.

What should I do if I get this PCAP question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Keep practising

More PCAP practice questions

Last reviewed: Jun 11, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This PCAP practice question is part of Courseiva's free Python Institute 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 PCAP exam.