Append is used to add element at the end of list. Element can be anything a number , string , another list etc. In Python, Append does not return any value.
Append() in Python:
In Python, append() is a built-in method that is used to add an element to the end of a list. In Python, lists are one of the most common data structures, and the append() method makes adding items to lists easy.
Example :
li=[1, 2 , 4 ]
li.append( 5)
li=[ 1 , 2 , 4 , 5 ]
Syntax :
# Adds an object (a number, a string or a another list) at the end of list
list_name.append(object)
#Append
li=[1,2,3]
#add a number
li.append(5)
print(li)
#add a string
li.append('PrepInsta')
print(li)
#add a list at end of the list
ext=[5, 6 , 7]
li.append(ext)
print(li)
Login/Signup to comment