Python 3.4 - Indexing and slicing
Indexing and slicing Indexing and slicing are two approaches, used to access or retrieve elements of a sequence datatype such as string, list, tuple etc. Indexing Indexing is used to access a single element at a time. We can use index number of an element of a sequence to access that particular element. Every element in a sequence such as string, list, tuple, bytes etc. has an index number. An index number starts from 0 (zero) in Python. So an index number is used to access an element . For example, in a string “india” the index number of first element ‘i’ is 0, the index number of second element ‘n’ is 1, the index number of third element ‘d’ is 2 and so on. The index number of last element ‘a’ is 4. So remember that, the indexing starts from 0 and ends at n-1 in a sequence of n length. In our case, string “india” has length 5 i.e. 5 characters or elements. So the indexing started from 0 and ended at 4 (n-1 or 5-1). Same concept applies to all the other sequences. See the im