Q:

python index method

>>> ["foo", "bar", "baz"].index("bar")
1
30
list.index(element)
13

fruits = ['apple', 'banana', 'cherry']
print(fruits.index("cherry"))
#--> 2
4
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
7
# Make the list
list = ['bananas', 'apples', 'watermellon']
# Print the word apples from the list
print(list[1])
2
# vowels list
vowels = ['a', 'e', 'i', 'o', 'i', 'u']

# index of 'e' in vowels
index = vowels.index('e')
print('The index of e:', index)

# element 'i' is searched
# index of the first 'i' is returned
index = vowels.index('i')

print('The index of i:', index)
0
#you can index in a string like:
string='cupcake'
string[0]#returns 'c'
#you can index in a list like:
list = ['red', 'blue', 'green']
list[0]#returns 'red'
list[0][0]#returns[0] of 'red' wich is r
0
list = ['apples', 'bananas']
list[0]
0

New to Communities?

Join the community