get character from string python code example
Example 1: get char from ascii value python
>>> chr(104)
'h'
>>> chr(97)
'a'
>>> chr(94)
'^'
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
>>>
Example 3: how to get any letter of a string python
Random = "Whatever"
words2 = Random.split(" ")
print('number of letters:')
print(len(Random))
while True:
ask = int(input("what letter do you want?"))
print(Random[ask-1])