PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#STRING SLICING!
str1 = "Hello World"
#DON'T FORGET THE SPACE COUNTS AS A CHARACTER - you could write code to ignore this...
print("Hello World!\n\n")
#whole string reversed - no start or end set, so everything included
print("Whole word reversed: " + str1[::-1])
#just "Hello" - only an end point included(one after the character you want to end on)
#no step means it assumes the step is 1
print("Just Hello with end point of 4 - wrong: " + str1[:4:])
print("Just Hello with an end point of 5 - right: " + str1[:5:])
#even letters! - includes the space as a character
#starts at 1 because otherwise it will print one then step 2 from there - which is how you get odd letters!
print("Even letters only: " + str1[1::2])
#print lo W - a start and end point included
print("print lo W: " + str1[3:7:])
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run