This course is currently a work in progress. Please join the waitlist to receive regular updates.
Remove an elememt from a list
To remove an element from List, use the remove()
method. The remove() method requires the index of the element to be removed from the list.
Following is an example of removing an element from a list:
Loading...
In the above example:
- The
remove()
method is used remove an item from the list. - The remove() method takes the index
1
to remove the second item from the list( The list index starts with 0.) - If the list index is invalid, the system will throw an
exception
.
Note
To remove all values from the list use the clear() method.
Try It Yourself
Loading...