python中的常用BIF(Built-In function):
1.count()
list1 = [123,456,789]
list6 = list1*6
list6.count(123)
结果:
6
2.index()
1)一个参数
list1 = [123,456,789]
list6 = list1*6
list6.index(123)
结果:
0
只返回第一个123的下标位置
2)三个参数
list1 = [123,456,789]
list6 = list1*6
list6.index(123)
list6.index(123,3,7)
结果:
3
3.reverse():翻转,跟大多数语言的reverse一样
4.sort():排序,从小到大排序
6.列表的赋值与拷贝
1)赋值
list1 = [123,456]
list2 = list1
list1.insert(1,789)
list1
[123,789,456]
list2
[123,789,456]
说明只是生成了一个指针指向同一个列表对象
2)拷贝
list1 = [123,456,789]
list2 = list1[:]
list1.insert(0,1)
list1
[1,123,456,789]
list2
[123,456,789]
说明生成了一个新的列表对象,list2指向它