9.6. List methodsΒΆ

Python provides methods that operate on lists. For example, append adds a new element to the end of a list:

Before you keep reading...

Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.

extend takes a list as an argument and appends all of the elements:

This example leaves t2 unmodified.

sort arranges the elements of the list from low to high:

Most list methods are void; they modify the list and return None. If you accidentally write t = t.sort(), you will be disappointed with the result.

You have attempted 1 of 7 activities on this page