Basj
0
Q:

how to index python

>>> ["foo", "bar", "baz"].index("bar")
1
30
#Example List
list = ['apples', 'bannas', 'grapes']
#Use Known Entites In The List To Find The Index Of An Unknown Object
Index_Number_For_Bannas = list.index('apples')
#Print The Object
print(list[Index_Number_For_Bannas])
9
# Make the list
list = ['bananas', 'apples', 'watermellon']
# Print the word apples from the list
print(list[1])
2
#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

New to Communities?

Join the community