my_string = "Hello World!"
my_string.index("l") # outputs 2
# this method only outputs the index of the first "l" value in the string/list
1) how to find index of a word in a string:
my_string = "Hello World!"
my_string.index("l")
2) how to find the first occurance of a word in a string:
print(verse.index('and'))
3)how to find the last occurance of a word in a string:
print(verse.rindex('you'))
#index with eval()
k=eval(input("enter the list"))
for i in range(len(k)):
print(k[i],"-->forward index",i,"backward index",-(len(k)-i))
#output
enter the list[1,9,5,7]
1 --> forward index 0 backward index -4
9 --> forward index 1 backward index -3
5 --> forward index 2 backward index -2
7 --> forward index 3 backward index -1
>>> word = 'Python'
>>> word[0] # character in position 0
'P'
>>> word[5] # character in position 5
'n'
TestString = "Python Is Fun"
print(TestString[2])
#This will print "t"
#printing it backwards would be
print(TestString[::-1])
#these an be stored in variables too.
a = TestString[0:5]
print(a)