Slicing extracts a portion of a string using [start:end]:
text = "Hello World"
print(text[0:5]) # "Hello"
print(text[6:11]) # "World"
print(text[:5]) # "Hello" (start defaults to 0)
print(text[6:]) # "World" (end defaults to length)
The end index is exclusive. text[0:5] gets characters , , , , but not .
You can also add a step: text[::2] gets every second character. text[::-1] reverses the string. Slicing never raises index errors. It just gives you what's available within the range.