Account
Categories

Python List append() Method


Definition:

If you need to add a value at the last position of a list, you will provide the value in the argument.

Now you will clearly understand the method through the flowchart .

List →  l = [10, 20, 30]

Index :   0      1      2  
          ↓      ↓      ↓
Value :  10     20     30  

Operation →  l.append(40)

Updated List →  [10, 20, 30, 40]

Index :   0      1      2      3  
          ↓      ↓      ↓      ↓
Value :  10     20     30     40  

Syntax:

list_name.append(value)

Example:

a = [10, 20, 30]
a.append(40)

Output:

Exercise

Add value 50 to the list a = [5, 10, 15] using append() in Python.