ScanSkill

append

append() function or method is used in python list to add an item to the end of the list.

Syntax

list.append(object)

Here,

  • object: Required. The item to append. Any valid type(string, number, object etc.)

Examples

>>> list1 = [1, 2]
>>> list1.append(3)
>>> list1
[1, 2, 3]
  • Tuple as an object or element
>>> list1 = [{1, 2, 3}, [1, 2, 3]]
>>> tuple1 = (1, 2, 3)
>>> list1.append( tuple1)
>>> list1
[{1, 2, 3}, [1, 2, 3], (1, 2, 3)]

Here, tuple1 is inserted at the end of list1. Similarly, you can add another list, set, etc.