The following exercises cover Lists in Python.
Exercise 1
Complete the syntax to create a list of strings, mylist
.
mylist = 'apple', 'banana', 'cherry'
Exercise 2
Print second element from the list mylist
.
mylist = ['apple', 'banana', 'cherry'] print(mylist[])
Exercise 3
Update second element in the list mylist
, to 'mango'
.
mylist = ['apple', 'banana', 'cherry'] = 'mango'
Exercise 4
Append an item 'mango'
to the list mylist
using list.append() method.
mylist = ['apple', 'banana', 'cherry'] mylist.()
Exercise 5
Remove second item from the list mylist
using List pop() method.
mylist = ['apple', 'banana', 'cherry'] mylist.()
Exercise 6
Print last item in the list mylist
using negative index.
mylist = ['apple', 'banana', 'cherry'] print(mylist[])
Exercise 7
Iterate over the items of the list mylist
using For loop.
mylist = ['apple', 'banana', 'cherry'] for item : print(item)