Exam PCAP-31-03 All QuestionsBrowse all questions from this exam
Question 18

Assuming that the snippet below has been executed successfully, which of the following expressions will evaluate to True? (Choose two.) string = 'python'[::2] string = string[-1] + string[-2]

    Correct Answer: B, C

    After executing the provided code snippet, 'python'[::2] results in 'pto'. Assigning string the value of its last two characters reversed ('ot'), we can evaluate the options. As 'len(string)' evaluates to 2, option A ('len(string) == 3') is false. 'string[0]' is 'o', so option B ('string[0] == 'o'') is true. 'string[0]' being equal to 'string[-1]' (both 'o') makes option C true. Finally, option D ('string is None') is false since string clearly holds the value 'ot'. Therefore, the correct answers are B and C.

Discussion
kstrOption: B

Sorry only B: string = 'python'[::2] string = string[-1] + string[-2] print(len(string) == 3 ) print(string[0] == 'o' ) print( string[0] == string[-1] ) print( string is None)

Dave304409Options: AB

A, B is correct string = 'python'[::2] print(string) pto R: print(len(string) == 3 ) string = string[-1] + string[-2] print(string) ot print(string[0] == 'o' )

DKAT2023Options: BC

B is the correct

kstrOption: C

Only C is True string = 'python'[::2] string = string[-1] + string[-2] print(len(string) == 3 ) print(string[0] == 'o' ) print( string[0] == string[-1] ) print( string is None)