2. Give at least three examples that show different features of string slices. Describe the feature illustrated by each example. Invent your own examples.
abc = [['a'], ['B'], ['c'], ['d']]
letters = []
count = 1
for letter in abc:
letters.append(letter*count)
count += 1
middle_elements = letters[1:3] # Two elements in the middle
last_element = letters[-1] # The last element
first_two = letters[0:2] # First two elements
first_of_last = letters[-1][0] # First element of the last element
Comments
Leave a comment