In this exercise on string slicing, we are asked to write a function that concatenates the last three letters of two different strings and returns them as a new string. Here is a screenshot of the instructions:
I learned how to slice lists before this exercise and I’ve learned how to use the
len() function before this exercise, and it doesn’t seem like slicing strings is all that different from slicing lists. I could be wrong, so please correct me if I am!
My question is this - why is the
len() function necessary for this exercise? In the hint in the screenshot, you can see that they suggest using the following code:
However, here is the code I wrote for this exercise:
new_string = first_name[-3:] + last_name[-3:]
Why is the
len() function necessary in this instance? I understand this particular lesson is discussing this function, but it just appears to be absolutely pointless to use it in this exercise. Am I missing something here?