6
AssignmentMultiple Choice

String Formatting

Question 6 • Introduction to Computer Science B – 4-232

You have previously used slicing with strings. What is the output? str = 'abcdef' print(str[2:5])

Answer
A
cde
B
bcde
C
cdef
D
bcd

Explanation

Python slicing includes the character at the starting index but stops before the ending index. In 'abcdef', index 2 is 'c', and the slice ends just before index 5, so it includes 'c', 'd', and 'e'. The output is cde, choice A.

AI-written and checked against the verified answer.