string index

The position number of a character in a string or an item in a list, counting from 0 at the left, used in square brackets as s[0].

In more detail

The last index is the length minus one, and negative indices count from the right, so s[-1] is the last character. Asking for an index past the end raises IndexError. Lists, tuples and other sequences index the same way.

Example

s = "computer"
s[0], s[-1]   # ("c", "r")

Related terms

Taught in

References

Certification courses