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

PCAP-31-03 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]

Show Answer
Correct Answer: BC

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

4 comments
Sign in to comment
kstrOption: B
Jun 5, 2024

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)

kstrOption: C
Jun 5, 2024

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)

DKAT2023Options: BC
Jun 28, 2024

B is the correct

Dave304409Options: AB
Jul 2, 2024

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' )