Exercises

For all exercises below consider the following list is given to you:

fruits = ["apple", "banana", "cherry"]

1. List access

Print the first element of the list. Then print the last element of the list.

2. List modifications

Change the value of the second element of the list to "orange". And add "lemon" to the end of the list.

3. List modifications-2

Add "kiwi" and "lemon" to the list, so that the final list looks like this:

["kiwi", "apple", "lemon", "banana", "cherry"]

4. List sorting

Add "kiwi" and "lemon" at the end to the list.

Sort the list alphabetically.

Now sort the list in descending alphabetical order, so that "kiwi" and "lemon" are the first two elements of the list.

5. List slicing

Print the first two elements of the list.

Print the last two elements of the list.

The output should be:

['apple', 'banana']
['banana', 'cherry']

6. List length

Print the length of the list.

Print the length of the list after adding "kiwi" and "lemon" to the list.

Print number of characters of the first element of the list.