Editor settings

General settings

Save settings

Learn to program with Python

Adding a new element to a list #

We can add a new element to the end of a list using the append() function. It takes a single argument, which is the element that needs to be added to the list.

For example:

my_list = ['apple', 'banana', 'cherry']
my_list.append('orange')
print(my_list) # Output: ['apple', 'banana', 'cherry', 'orange']

Exercise #

  • Use the function append() any value to the variable my_list

Tests #

  • The length of my_list should have more than 4 elements
  • Use the function append()
  • Do not change the first line of the code
Output will be displayed here