Certified Associate in Python Programming (PCAP-31-03) — Question 103
Assuming that the snippet below has been executed successfully, which of the following expressions will evaluate to True? (Choose two.)
string = 'SKY'[::-1]
string = string[-1]
Answer options
- A. len(string) == 1
- B. string[0] == 'Y'
- C. string[0] == string[-1]
- D. string is None
Correct answer: A, C
Explanation
The correct answers are A and C because after executing the snippet, 'string' holds the value 'Y', making len(string) equal to 1 (True) and string[0] equal to string[-1] (both are 'Y', also True). Options B and D are incorrect as string[0] is 'Y' and not equal to 'Y', and string is not None.