列表的方法

list1 + list2 是把两个列表中的元素组合到一块

list1.count( )  查看列表中  有几个某元素

list1.index(value,start,stop)查看列表中某个元素的索引

list1.sort(reverse= )  默认reverse是False,可以改成True  是从大到小排序。

list2 = list1  ; list3 = list1[ : ]区别  后者直接复制了一个新的列表,而前者是一个新的标签指向了列表1 在内存中的东西,如果

列表1 改变那么列表2 也会改变,要复制列表的话一般用到后者。

list4 =list1.copy( ) 复制一个列表

list1.clear 将列表变为一个空列表

list1.reverse( )  将列表中的元素逆序排列

list4 = list1 * 3 

列表推导式:    list1 = [(x,y) for x in range(10) for y in range(10) if x %2 == 0 if y %2 !=0]


猜你喜欢

转载自blog.csdn.net/qq_21786897/article/details/80110652