2. Give at least three examples that show different features of string slices. Describe the feature illustrated by each example. Invent your own examples.
#python slicing is about obtaining a substring, this can be done in different ways as illustrated in the examples below. Below are some featurs of string slices
#We can select letter in the string if know the index e.g
string = 'Joseph'
string[3]
'e'
#we can select more than one letter using the ':'
string = 'Joseph'
string[3:]
'eph'
string = 'Joseph'
string[:3]
'Jos'
#we can also get the reverse of the string up to a particular index
string = 'Joseph'
string[::-1]
'hpesoJ'
Comments
Leave a comment