Question Detail

COS 102 Advanced Text Processing Objective Question

Question

What is the result of the following Python string slice:
word = "Python"
print(word[2:5])
Options
A tho
Correct Answer
B th
C hon
D pyt
Correct Answer

Option A is the correct answer.

Detailed Explanation

For word[2:5], slicing starts at index 2 ('t') and goes up to, but not including, index 5. The characters at indices 2, 3, and 4 are 't', 'h', and 'o' respectively, resulting in 'tho'.

Hint

Identify the characters at indices 2, 3, and 4 in 'Python'.

Question Info