Elements of a sequence can be referred to using square brackets and a zero-based index, just as with arrays in Java.
For example, (4, 5, 6)[2]
is 6
.
Python also supports negative indices, which count down from the end of the sequence. For instance,
(4, 5, 6)[-3]
is the third element from the end of (4, 5, 6)
, which is 4
.
Similarly, (4, 5, 6, 7)[-3]
is 5
.
String indexing in Python behaves a little differently than the indexing of other sequences. Because Python has no
character type, individual characters are automatically converted to strings. For example,
'Python'[0]
is not the character "P" but a string, 'P'
, that has "P" as its only
character.
Fill in the placeholders so that the actual outputs match the expected outputs.