Courseiva
Strings →easyMultiple Choice

PCAP Strings Practice Question

A programmer has a string 'apple,banana,orange' and wants to get a list ['apple', 'banana', 'orange']. Which method should be used?

⚠ Common exam trap

The PCAP exam often tests the confusion between `split()` and `partition()` — candidates mistakenly think `partition()` returns a list of all parts, but it only splits at the first occurrence and returns a tuple, not a list of all comma-separated items.

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

✓

s.split(',')

`s.split(',')` splits the string `'apple,banana,orange'` at each comma delimiter, returning a list of substrings: `['apple', 'banana', 'orange']`. This method is designed to break a string into a list based on a specified separator, making it the exact tool for this task.

Answer analysis

Option-by-option breakdown

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

  • ✗

    s.splitlines()

    Why it's wrong here

    s.splitlines() is incorrect because it splits the string on line-boundary characters such as '\n', '\r', '\r\n', or '\v', not on commas. If the string contains only comma-separated words and no newline characters, splitlines() returns a list with the entire original string as its only element. It also cannot be called with a comma separator argument, so it will never produce the individual apple/banana/orange pieces.

  • ✗

    s.partition(',')

    Why it's wrong here

    s.partition(',') is incorrect because it only divides the string at the first comma and returns a three-element tuple: (head, separator, tail). For 'apple,banana,orange', it returns ('apple', ',', 'banana,orange'), leaving the second comma unprocessed and the result in tuple form rather than a list of all three fruits. To extract every comma-separated field, you need a method that repeats the split, not partition.

  • ✗

    s.join(',')

    Why it's wrong here

    s.join(',') is incorrect because str.join() is a method of the separator string and expects an iterable of strings as its argument; calling it on s means s is used as the separator. Here, the argument ',' is just a single-character string, so the result is simply ',' since joining one element with any separator yields that element. Even conceptually, join() is the opposite operation to split() and cannot parse a delimited string into a list; the correct form would be ','.join(...) on a list.

  • ✓

    s.split(',')

    Why this is correct

    s.split(',') is correct because str.split() with a specified separator splits the string at every occurrence of that separator and returns a list of the substrings in between, with the separator removed. For the string 'apple,banana,orange', this yields ['apple', 'banana', 'orange'], exactly the three separate fruits the programmer wants. This is the standard built-in method for turning a delimited string into a list of parts.

About these practice questions

This PCAP question is part of Courseiva's 421-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.