String indexing and slicing
Indexing and slicing are crucial parts of programming. Indexing and slicing are regularly used in lists, a topic that we will cover in Chapter 2, Python Data Structures. In data analysis, indexing and slicing DataFrames is essential to keep track of rows and columns, something you will practice in Chapter 10, Data Analytics with pandas and NumPy.
Indexing
The characters in strings exist in specific locations. In other words, their order counts. The index is a numerical representation of where each character is located. The first character is at index 0, the second character is at index 1, the third character is at index 2, and so on.
Note
We always start at 0 when indexing in computer programming!
Consider the following string:
destination = 'San Francisco'
'S'
is in the 0th index, 'a'
is in the 1st index, 'n'
is in the 2nd index, and so on, as shown in the following table: