Python String Operations
Indexing It is helpful to think of a string as an ordered sequence. Each element in the sequence can be accessed using an index represented by the array of numbers: The first index can be accessed as follows: [Tip]: Because indexing starts at 0, it means the first index is on the index # Print the first element in the string print ( Name [ 0 ]) We can access index 6: # Print the element on index 6 in the string print ( Name [ 6 ]) Moreover, we can access the 13th index: # Print the element on the 13th index in the string print ( Name [ 13 ]) N egative Indexing We can also use negative indexing with strings: Negative index can help us to count the element from the end of the string. The last element is given by the index -1: # Print the last element in the string print ( Name [ - 1 ]) The first element can be obtained by index -15: # Print the first element in the string print ( Name [ - 15 ]) We can find the number of characters in a string by using len , short for length:...