How to get char from string by index?

后端 未结 7 1045
青春惊慌失措
青春惊慌失措 2020-11-29 04:25

Lets say I have a string that consists of x unknown chars. How could I get char nr. 13 or char nr. x-14?

7条回答
  •  天涯浪人
    2020-11-29 04:43

    This should further clarify the points:

    a = int(raw_input('Enter the index'))
    str1 = 'Example'
    leng = len(str1)
    if (a < (len-1)) and (a > (-len)):
        print str1[a]
    else:
        print('Index overflow')
    

    Input 3 Output m

    Input -3 Output p

提交回复
热议问题