piton

Python List Append

Python List Append

The list is one of the important data structures in Python that arranges the elements in a sequence. The append() is the built-in function in Python that inserts the element or items to the end of the list and essentially increases the length of the list by one. This article explains the Python list append() function with examples.

Syntax of the append() function

The syntax of the append() function is as follows:

listObj.append(item)

The append() function is called with the name of the list object. It only takes one parameter. We pass the item as an argument.

Examples

#creating a list of numbers
myList = [1,2,3,4,5,6]
#apending the list
myList.append(7)
#printing the updated list
print("The updated list is:", myList)
#creating a list of strings
myList = ['a','b','c','d']
#apending the list
myList.append('e')
myList.append('f')
myList.append('g')
#printing the updated list
print("The updated list is:", myList)
#creating a list of mix data types
myList = ['a',1,2,3,'b','c','d',5]
#apending the list
myList.append(6)
myList.append('Kamran')
myList.append('Sattar')
myList.append('Awaisi')
#printing the updated list
print("The updated list is:", myList)

Output

In the output it can be observed that all the items appended in the lists are added to the end of the lists.

We can also append a list in another list. The appended list be added at the end. Let's append a list in another list.

#creating a list of numbers
myList1 = [1,2,3,4,5,6]
#creating a list of strings
myList2 = ['a','b','c','d']
# appending the list
myList1.append(myList2)
print(myList1)

Output

Conclusion

Python provides many built-in data structures like lists, tuples, dictionaries, etc. The list arranges the items in sequence. We can add the elements in the list after declaring the list. The append() is a built-in function that inserts the items at the end of the list. This article explains the list append() function with examples.

Ubuntu'da Oynanacak En İyi 10 Oyun
Windows platformu, günümüzde doğal olarak Windows'u desteklemek için geliştirilen oyunların büyük bir yüzdesi nedeniyle oyun oynamak için hakim platfo...
Linux için En İyi 5 Arcade Oyunu
Günümüzde bilgisayarlar oyun oynamak için kullanılan ciddi makinelerdir. Yeni yüksek puanı alamazsan, ne demek istediğimi anlayacaksın. Bu yazıda, bug...
Wesnoth 1 Savaşı.13.6 Geliştirme Yayınlandı
Wesnoth 1 Savaşı.13.Geçen ay yayınlanan 6. sürüm, 1. sürümdeki altıncı geliştirme sürümüdür.13.x serisi ve özellikle kullanıcı arayüzü için bir dizi i...