Strings, the good, the bad, and the ugly¶
String indexing¶
The character components of a string can be accessed the same way that a list can be. Each character as a positional assignment, so for example:
-11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 |
h | e | l | l | o | w | o | r | l | d | |
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
You can index and slice a string just like you would a list, so for example:
In [1]: my_string = 'hello world'
In [2]: my_string[0]
Out[2]: 'h'
In [3]: my_string[-1]