1my_string = "Hello World!"
2
3my_string.index("l") # outputs 2
4# this method only outputs the index of the first "l" value in the string/list
11) how to find index of a word in a string:
2 my_string = "Hello World!"
3
4 my_string.index("l")
5
62) how to find the first occurance of a word in a string:
7 print(verse.index('and'))
8
9
10 3)how to find the last occurance of a word in a string:
11 print(verse.rindex('you'))
12
1# vowels list
2vowels = ['a', 'e', 'i', 'o', 'i', 'u']
3
4# index of 'e' in vowels
5index = vowels.index('e')
6print('The index of e:', index)
7
8# element 'i' is searched
9# index of the first 'i' is returned
10index = vowels.index('i')
11
12print('The index of i:', index)
1#you can index in a string like:
2string='cupcake'
3string[0]#returns 'c'
4#you can index in a list like:
5list = ['red', 'blue', 'green']
6list[0]#returns 'red'
7list[0][0]#returns[0] of 'red' wich is r