Certified Associate in Python Programming (PCAP-31-03) — Question 17
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]
Answer options
- A. len(string) == 3
- B. string[0] == 'o'
- C. string[0] == string[-1]
- D. string is None
Correct answer: A, B
Explanation
The correct answers A and B are true because after executing the snippet, 'string' becomes 'on' (length 2), and the first character is 'o'. Option C is incorrect as 'string[0]' is 'o', which is not equal to 'n' (string[-1]). Option D is false because 'string' holds a value, not None.