String Indexing

Create a string

string = 'Strings are defined as ordered collections of characters.'

Print the entire string

string[:]
'Strings are defined as ordered collections of characters.'

Print the first three characters

string[0:2]
'St'

Print the first three characters

string[:2]
'St'

Print the last three characters

string[-3:]
'rs.'

Print the third to fifth character

string[2:4]
'ri'

Print the first to the tenth character, skipping every other character

string[0:9:2]
'Srnsa'

Print the string in reverse

string[::-1]
'.sretcarahc fo snoitcelloc deredro sa denifed era sgnirtS'