Exam PCAP-31-03 All QuestionsBrowse all questions from this 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)

    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
kstrOption: B

B the answer

DKAT2023Option: B

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