Excercise 2

Working with lists

Do the following excercises to get familiar with the python interpreter. Use the python interpreter to write line instructions to python and interact with your computer, like you normally would do in a terminal.

Excercise 1


To solve many of these little excercises, you will have to search for operations and methods in the internet. Alternatively you can go to this website where you can find information about different methods built in python. It is common practice while coding to search for solutions or query questions about how to do something in python.

Write the following commands in the python interpreter

>>> fruits = ['bananas','apples','strawberries']
>>> print(fruits)

Add an item to the list

  • Find a way to add a new entry or fruit to the list (for example blueberry).

  • Print the result in the interpreter to check that the fruit was added.

Remove bananas from the list

  • Look for a method that can help you remove bananas from the list

Try the following in your interpreter

>>> print(fruits[0])
  • Think about what did you get and what does it mean.

  • Create a new variable strawberries

  • Get the strawberries item inside the list and store it in a new variable

Insert grapes right after apples in the fruits list Lists are one common data type in python.

A Python list is a native data type that serves as a container for other Python objects in a specified order. Python lists can contain other lists and are great for simple data structures. They also map well to more complex structures or even databases if you decide you want to develop your script further.