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

posted @ 2014-07-13 15:06  平静缓和用胸音说爱  阅读(209)  评论(0编辑  收藏  举报