Join Regular Classroom : Visit ClassroomTech

append() method in Python List

It is a method in list that appends a list or an argument as a single element to the end of the list. The list length increases by 1 (only). It modifies the existing list. It doesn’t return a value.

Syntax: list.append(element)

Don’t know what is copy method in python? Read: copy() method in Python List

Example 1:

s=["Name", "codewindow", "Country", "India"]
s.append("democracy")
print(s)

Output:

[‘Name’, ‘codewindow’, ‘Country’, ‘India’, ‘democracy’]

Explanation:

Here the element “democracy” is appended to the end of the list as a single element.

Example 2:

s=["Name", "codewindow", "Country", "India"]
s.append(["democracy", "secular"])
print(s)

Output:

[‘Name’, ‘codewindow’, ‘Country’, ‘India’, [‘democracy’, ‘secular’]]

Explanation:

Here the list “[“democracy”, “secular”]” is appended to the end of the original list as a single element. The length of the list has increased by one.


You Missed

Also Checkout