Page 77 -
P. 77
offset values
Find characters inside the text
The computer keeps track of individual characters by using two pieces
of information: the start of the string and the offset of an individual
character. The offset is how far the individual character is from the start of
the string.
We are at the start of the
string and, as we have moved
zero places, the offset is 0.
The first character in a string has an offset of 0, because it is zero
characters from the start. The second character has an offset of 1, and
so on:
Offset of 2
Offset of 1
Offset
values As we start counting from 0, the
offset values are always one less
than their actual position.
Remember: the first character
has index 0, so we are “off
The offset value is always 1 less than the position. Python lets you read a single by one" when referring to an
character from a string by providing the offset value in square brackets individual character.
after the variable name. Because the offset value is used to find a character,
it is called the index of the character:
42 Chapter 2