Python list append

In this article, you’ll see how to append a list in Python. The append method is used to add an element to a list. It adds an element at the end of the list. The append method takes only one argument. The argument can be integer, string, float, or any other data type such as a list. I highly recommend you get the “Python Crash Course Book” to learn Python.

Add integer to a list

a = [7, 14, 21, 28, 35]
a.append(60)
print(a)

Output:

[7, 14, 21, 28, 35, 60]

Add string to a list

a = [10, 35, 40, 60, 70]
a.append('Hello')
print(a)

Output:

[10, 35, 40, 60, 70, 'Hello']

Add list

a = [10, 35, 40, 60, 70]
a.append([75,80, 85])
print(a)

Output:

[10, 35, 40, 60, 70, [75, 80, 85]]

Leave a Comment

Your email address will not be published.