PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 54


If you want to transform a string into a list of words, what invocation would you use? (Choose two.)

Expected output:

Code:

Show Answer
Correct Answer: AC

To transform the string 'The Catcher in the Rye' into a list of words, using s.split() will break the string at all whitespace, resulting in a list of words as desired. Similarly, using s.split(' ') will split the string at each space, which also results in the desired list of words. Therefore, both s.split() and s.split(' ') are correct invocations for achieving the expected output.

Discussion

6 comments
Sign in to comment
ziadzidaneOptions: AC
Sep 29, 2022

A and C: don't forget a space here : s.split(' ') to avoid the error!

SuvabrataOptions: AC
Jun 6, 2022

Correct answer is A. s.split(' ') will give ValueError: empty separator

macxszOptions: AC
May 3, 2022

A. s.split () C. s.split (' ')

ciccio_benzina
Sep 5, 2022

only A is right. Error with C

Premi9Options: AC
Apr 8, 2023

a is correct C works only if we have space in between quotes s.split(' ') since there is space C is also correct

CC_DC
Jul 12, 2023

This code is so jacked up wrong. The uppercase S should be a lowercase s, the number 1 should l (letter 'l') and the F in For should be lowercase. Without these changes, the code will not even compile.

neked
Sep 13, 2023

This is due to copying the OCR results of screenshots in batch without looking