Question Detail

COS 102 Advanced Text Processing Objective Question

Question

According to the document, what is the primary difference between indexing and slicing in string manipulation?
Options
A Indexing is used for numbers, while slicing is for text.
B Indexing retrieves a single character, while slicing extracts a substring or segment.
Correct Answer
C Indexing modifies the original string, while slicing creates a new one.
D Indexing works from the end of the string, while slicing works from the beginning.
Correct Answer

Option B is the correct answer.

Detailed Explanation

The document states: 'If indexing lets you look at a single character, Slicing lets you cut out an entire substring or segment.' This clearly defines their primary difference.

Hint

Think about what 'a single crumb' versus 'a clean slice of text' refers to in the bread analogy.

Question Info