Common List Operations
Explore some of the properties and utilities that come in-built with the list data structure.
Adding elements
All the elements of a list cannot always be specified beforehand and there’s a strong possibility that we’ll want to add more elements during runtime.
The append()
method can be used to add a new element at the end of a list
. The following template must be followed:
a_list.append(newElement)
Here’s an example:
Press + to interact
num_list = [] # Empty listnum_list.append(1)num_list.append(2)num_list.append(3)print(num_list)
Note: In the ...
Access this course and 1400+ top-rated courses and projects.