//Sample Solution
Slicing 'n' Dicing
So far we've extracted only single characters. But what if we wanted to extract more than one character, like "water" from "watermelon"? We can use something called slicing to do this. Its syntax is similar to that of indexing, but instead of just one index, you give two indices (numbers) separated by a colon.
For example, str[start:end] will give you the part of the string str starting at index start and going up to BUT NOT INCLUDING the index end.
Use slicing to get "water" from the string "watermelon".
"watermelon"[0:5]
=> 'water'
I love watermelons! Let's keep going.
No comments:
Post a Comment