String Slicing (Solution)
My task is to slice bazinga to get zing. So I’ll start off by assigning the string
"bazinga" to a variable. So I’m just going to call it
word in that case. Is bazinga a real word? Okay, here we have
"bazinga", and then I’m going to use slice notation to get out the
zinga part of it.
and inside of the square brackets, you have to put in the indexes that you want to use. String indexing starts with zero, so
b is at the index zero,
a is the index one, and then we have
z at the index two.
And that could be by saying
word and again starting at two and then going up to—so this was two, then the
i is three, and
n is four, and the
g is five, and then the
a is six, and you have to specify one plus the last character that you want to get.
Become a Member to join the conversation.