Append () in Python
Append() in Python :
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)
Code 1:
Run
#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)
Output :
[1, 2, 3, 5]
[1, 2, 3, 5, 'PrepInsta']
[1, 2, 3, 5, 'PrepInsta', [5, 6, 7]]
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment