Exercises:

  1. Exercise 1: Create a list of 5 different fruits and print the list.

    • Hint: Use the append() method to add fruits to your list.
    • Solution:
      fruits = []
      fruits.append('Apple')
      fruits.append('Banana')
      fruits.append('Cherry')
      fruits.append('Date')
      fruits.append('Elderberry')
      print(fruits)
      
  2. Exercise 2: Add ‘Fig’ to the end of your fruit list and print the list.

    • Hint: Use the append() method again.
    • Solution:
      fruits.append('Fig')
      print(fruits)
      
  3. Exercise 3: Insert ‘Blueberry’ at the second position in your fruit list and print the list.

    • Hint: Use the insert() method.
    • Solution:
      fruits.insert(1, 'Blueberry')
      print(fruits)
      
  4. Exercise 4: Remove ‘Date’ from your fruit list and print the list.

    • Hint: Use the remove() method.
    • Solution:
      fruits.remove('Date')
      print(fruits)
      
  5. Exercise 5: Sort your fruit list in alphabetical order and print the list.

    • Hint: Use the sort() method.
    • Solution:
      fruits.sort()
      print(fruits)