人若有情死得早 发表于 2017-6-15 22:21:47

012列表:一个打了激素的数组3

1.列表的一些常用操作符
1)比较操作符
>>> list1 =
>>> list2 =
>>> list1 > list2
False
>>> list1 =
>>> list2 =
>>> list1 > list2
False
2)逻辑操作符
>>> list3 =
>>> (list1 < list2) and (list1 == list3)
True
3)连接操作符
>>> list4 = list1 +list2
>>> list4

>>> list1 + '小甲鱼'
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
    list1 + '小甲鱼'
TypeError: can only concatenate list (not "str") to list
4)重复操作符
>>> list3

>>> list3 * 3

>>> list3 *= 3
>>> list3

>>> list3 *= 5
>>> list3

5)成员关系操作符
>>> 123 in list3
True
>>> '小甲鱼' not in list3
True
>>> 123 not in list3
False
>>> list5 = ,456]
>>> '小甲鱼' in list5
False
>>> '小甲鱼' in list5
True
>>> list5
'牡丹'
2.列表的小伙伴们(官方的来讲:列表类型的内置函数BIF)
>>> dir(list)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
1)count:计算它的参数在列表中出现的次数
>>> list3.count(123)
15
2)index:索引,返回它的参数在列表中的位置
>>> list3.index(123)
0
>>> list3.index(123,3,7)
4
3)reverse:将整个列表原地翻转
>>> list3.reverse()
>>> list3

4)sort:用指定的方式对列表的成员进行排序
>>> list6 =
>>> list6.sort()#从小到大排
>>> list6

>>> list6.sort(reverse=True) #从大到小排
>>> list6

3.关于分片‘拷贝’概念的补充
>>> list7 = list6[:]
>>> list7

>>> list8 = list6
>>> list8

>>> list6.sort()
>>> list6

>>> list7

>>> list8
页: [1]
查看完整版本: 012列表:一个打了激素的数组3