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

PCAP-31-03 Exam - Question 48


What is the expected behavior of the following code?

the_string = ',,'.join(('alpha', 'omega'))

the_list = the_string.split(',')

print(',' in the list)

Show Answer
Correct Answer: A

The given code joins the tuple ('alpha', 'omega') into the string 'alpha,,omega' with ',,' as the separator. Then it splits the string 'alpha,,omega' by a comma, resulting in the list ['alpha', '', 'omega']. The print statement checks if the comma character ',' is in the list, which it is not, hence the output will be False.

Discussion

2 comments
Sign in to comment
DKAT2023Option: B
Jul 12, 2024

print(',' in the list) should be : print(',' in the_list)

kstrOption: B
Jul 12, 2024

B the answer