PCAP-31-03 Exam QuestionsBrowse all questions from this exam

PCAP-31-03 Exam - Question 15


What is the expected behavior of the following code?

the_list = "alpha;beta;gamma".split(";")

the_string = ''.join(the_list)

print(the_string.isalpha())

Show Answer
Correct Answer: A

The code first splits the string 'alpha;beta;gamma' by the semicolon delimiter, resulting in the list ['alpha', 'beta', 'gamma']. Then, it joins this list into a single string 'alphabetaGamma' with an empty string as the separator. Finally, the isalpha() method is called on this new string, which checks if all characters in the string are alphabetic. Since 'alphabetaGamma' consists only of alphabetic characters, print(the_string.isalpha()) will output True.

Discussion

2 comments
Sign in to comment
DKAT2023Option: D
Jun 28, 2024

D is the correct , the_string = ".join(the_list) should be : the_string = "".join(the_list) so it raises an exception

Dave304409Option: D
Jul 2, 2024

D is correct

Dave304409
Jul 4, 2024

Sorry the answer correct is A