List methods

Python provides methods that operate on lists. For example, append adds a new element to the end of a list, extend takes a list as an argument and appends all of the elements:

                       

And this example leaves t1 unmodified.

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

 

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

 

 

from Thinking in Python

原文地址:https://www.cnblogs.com/ryansunyu/p/3841119.html