7 of 151 menu

The append method

The append method adds an element to the end of the list. In the method parameter, we specify the element we need to add.

Syntax

list.append(what we want to add)

Example

Let's add the line 'ef' to our list:

lst = ['ab', 'cd'] lst.append('ef') print(lst)

Result of code execution:

['ab', 'cd', 'ef']

See also

  • method clear,
    which removes all elements of a list
  • method copy,
    which copies the list
  • method extend,
    which adds elements from the specified object to the list
  • function len,
    which returns the length of the list
enru