Complete the code to get the first three characters of the string.
text = "hello" slice = text[[1]] print(slice)
To get the first three characters, we slice from index 0 up to (but not including) 3.
Complete the code to get the last two characters of the string.
text = "world" slice = text[[1]] print(slice)
Using negative indices, -2: means from the second last character to the end.
Fix the error in the code to reverse the string using slicing.
text = "python" reversed_text = text[[1]] print(reversed_text)
The slice ::-1 reverses the string by stepping backwards one character at a time.
Fill both blanks to get every second character from index 1 to 6.
text = "abcdefghij" slice = text[[1]:[2]:2] print(slice)
Start at index 1 and go up to (but not including) index 6, stepping by 2 to get every second character.
Fill all three blanks to extract characters from index 2 to 8 skipping every 3rd character.
text = "abcdefghijklm" slice = text[[1]:[2]:[3]] print(slice)
Start at index 2, go up to (not including) 8, stepping by 3 to skip every 3rd character.