Certified Associate in Python Programming (PCAP) — Question 84
Assuming that the snippet below has been executed successfully, which of the following expressions evaluate to True? (Choose two.) string = 'SKY'[::-1] string = string[-1]
Answer options
- A. string[0] == 'Y'
- B. string[0] == string [-1]
- C. string is None
- D. len(string) == 1
Correct answer: B, D
Explanation
The variable 'string' is assigned the value 'Y' after reversing 'SKY', making string[0] and string[-1] both equal to 'Y', which confirms that option B is true. Additionally, since 'string' is now 'Y', its length is 1, validating option D. Option A is incorrect as string[0] is 'Y', not equal to 'Y', and option C is false because 'string' is not None.