In this exercise, the list slice shows a start and end point. Will a slice work without specifying the end?
Answer
Yes, it is possible to use a slice without specifying the end. In that case, the slice will return the list from the start point through the end of the list. This would be useful if you wanted to remove a known number of items from the start of the list and keep the remainder.
In the following example code, a list is sliced using a defined start and end point and then again specifying only the start.
colors = ['red', 'green', 'blue', 'yellow', 'orange']
# Values from index 1 to less than 4 = ['green', 'blue', 'yellow']
print(colors[1:4])
# Start at index 1 till end = ['green', 'blue', 'yellow', 'orange']
print(colors[1:])
employees += "john"
['Michael', 'Dwight', 'Jim', 'Pam', 'Ryan', 'Andy', 'Robert', 'carlos', 'j', 'o', 'h', 'n']
I added in carlos using append as discussed above, then tried to use += and it separates the letters in john. Not sure what is different? Thanks
The string, "john", was converted to a list of its component characters in order for it to be concatenated to the list of employees. Try placing "john" within its own list, instead, in order to perform the concatenation, as follows: