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.

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

Offset of 2

Ottsei values

Offset of

As we start counting from 0, the offset values are aUys one less than their actual position.

As we start counting from 0, the offset values are aUys one less than their actual position.

Remember: the -first character

The offset value is always 1 less than the position. Python lets you read a single character from a string by providing the offset value in square brackets after the variable name. Because the offset value is used to find a character, it is called the index of the character:

has index o, so we are Vff

by one when referring to an individual character.

The offset value is always 1 less than the position. Python lets you read a single character from a string by providing the offset value in square brackets after the variable name. Because the offset value is used to find a character, it is called the index of the character:

by one when referring to an individual character.

Was this article helpful?

0 0

Post a comment