get char at index in string in python code example
Example 1: parse first characters from string python
first_chars = sample_str[0:3]
print('First 3 characters: ', first_chars)
First 3 characters: Hel
Example 2: python char at
>>> s = "python"
>>> s[3]
'h'
>>> s[6]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: string index out of range
>>> s[0]
'p'
>>> s[-1]
'n'
>>> s[-6]
'p'
>>> s[-7]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: string index out of range
>>>