【python】列表
>>> mix = [2,3.4,"abc",'中国',True,['ab',23]]
>>> mix
[2, 3.4, 'abc', '中国', True, ['ab', 23]]
>>> nothing = []
>>> nothing
[]
>>> len(mix)
6
>>> mix.append('飞狐外传')
>>> mix
[2, 3.4, 'abc', '中国', True, ['ab', 23], '飞狐外传']
>>> len(mix)
7
>>> mix.extend(['雪山飞狐',"神雕侠侣"])
>>> mix
[2, 3.4, 'abc', '中国', True, ['ab', 23], '飞狐外传', '雪山飞狐', '神雕侠侣']
>>> len(mix)
9
>>> mix.insert(1,"天龙八部")
>>> mix
[2, '天龙八部', 3.4, 'abc', '中国', True, ['ab', 23], '飞狐外传', '雪山飞狐', '神雕侠侣']
>>> mix[2]
3.4
>>> mix.remove("飞狐外传")
>>> mix
[2, '天龙八部', 3.4, 'abc', '中国', True, ['ab', 23], '雪山飞狐', '神雕侠侣']
>>> len(mix) #求数组长度
9
>>> del mix[0] #del mix会删掉整个列表
>>> mix
['天龙八部', 3.4, 'abc', '中国', True, ['ab', 23], '雪山飞狐', '神雕侠侣']
>>> mix.pop()
'神雕侠侣'
>>> mix
['天龙八部', 3.4, 'abc', '中国', True, ['ab', 23], '雪山飞狐']
>>> name=mix.pop()
>>> name
'雪山飞狐'
>>> mix.pop(0)
'天龙八部'
>>> mix[1:4]
['abc', '中国', True]
>>> mix
[3.4, 'abc', '中国', True, ['ab', 23]]
>>> mix[:3]
[3.4, 'abc', '中国']
>>> mix[:]
[3.4, 'abc', '中国', True, ['ab', 23]]
>>> mix[2:]
['中国', True, ['ab', 23]]
>>>
>>> arr1 = [1,2]
>>> arr2 = [2,1]
>>> arr1 < arr2
True
>>> #只比较第一个元素
>>> arr3 = arr1 + arr2
>>> arr3
[1, 2, 2, 1]
>>> arr1 * 3
[1, 2, 1, 2, 1, 2]
>>> arr1
[1, 2]
>>> arr1 *=3
>>> arr1
[1, 2, 1, 2, 1, 2]
>>> 1 in arr1
True
>>> '令狐冲' not in arr2
True
>>> arr4 = [1,['a',2],3]
>>> 2 in arr4
False
>>> ['a',2] in arr4
True
>>> 2 in arr4[1]
True
>>> arr4[1][0]
'a'
>>> 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']
>>> arr1.count(2)
3
>>> arr1.index(2)
1
>>> arr1.index(2,2,5)
3
>>> arr1
[1, 2, 1, 2, 1, 2]
>>> arr4
[1, ['a', 2], 3]
>>> arr4.reverse()
>>> arr4
[3, ['a', 2], 1]
>>> arr1.sort()
>>> arr1
[1, 1, 1, 2, 2, 2]
>>> arr1.sort(reverse=True)
>>> arr1
[2, 2, 2, 1, 1, 1]
>>> arr1 = [2,3,1]
>>> arr1
[2, 3, 1]
>>> arr2 = arr1[:]
>>> arr3 = arr1
>>> arr2
[2, 3, 1]
>>> arr3
[2, 3, 1]
>>> arr1.sort()
>>> arr1
[1, 2, 3]
>>> arr2
[2, 3, 1]
>>> arr3
[1, 2, 3]
>>>