1my_list = ["pizza", "soda", "muffins"]
2
3my_list[0] # outputs "pizza"
4my_list[-1] # outputs the last element of the list which is "muffins"
5my_list[:] # outputs the whole list
6my_list[:-1] # outputs the whole list except its last element
7
8# you can also access a string's letter like this
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
1fruits = ['apple', 'banana', 'mango', 'cherry']
2
3for fruit in fruits:
4 print(fruit)
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# Make the list
2list = ['bananas', 'apples', 'watermellon']
3# Print the word apples from the list
4print(list[1])