Show Answer


The correct answer is B.

OBJ-4.4: When evaluating the code s[-12:-7], you would receive “Train” in response. Within Python, characters in a string can be accessed by their index location. If the string (s) is “”, then each letter from left to right is referenced as s[0] to s[15]. If you want to reference it from right to left, you simply use a negative number, such as s[-12:-7]. The format for the array is [start:end:increment], so s[-12:-7] is evaluated as starting with the 12th position from the right (T in, count until it reaches the 7th position from the right, incrementing by the default value of 1 each time. This would display, from the end of the word, the 12th position (T), 11th position (i), 10th position (o), 9th position (i), and 8th position (T), and then stop. Note that when counting positions from the right, you begin counting at 1. When counting from the left, you start with position 0 and work up from there.

Hide Answer