List operations

The + operator concatenates lists:

                       

Similarly, the * operator repeats a list a given number of items:

 

List slices

The slice operator also works on lists:

 

If you omit the first index, the slice starts at the beginning. If you omit the second, the slice goes to the end. So if you omit both, the slice is a copy of the whole list.

 

from Thinking in Python

posted @ 2014-07-13 14:51  平静缓和用胸音说爱  阅读(289)  评论(0)    收藏  举报