### Python3数组常用操作

（1）创建数组

``# Create an arraya = []``

(2)添加元素

``# Add element# Time Complexity:O(1)a.append(1)a.append(2)a.append(3)# [1,2,3]print(a) # Insert element# Time Complexity:O(N)a.insert(2, 99)# [1,2,99,3]print(a)``

(3)访问元素

``# Access element# Time Complexity:O(1)temp = a# 99print(temp)``

(4)更新元素

``# Update element# Time Complexity:O(1)a = 88# [1,2,88,3]print(a)``

(5)删除元素

``# Remove element# Time Complexity:O(N)a.remove(88)# [1,2,3]print(a)a.pop(1)# [1,3]print(a)# Time Complexity:O(1)a.pop()# print(a)``

(6)获取数组长度

``a = [1,2,3] # Get array sizesize = len(a)# 3print(size)``

(7)遍历数组

``# Iterate array# Time Complexity:O(N)for i in a:    print(i)for index, element in enumerate(a):    print("Index at ", index, "is : ", element)for i in range(0, len(a)):    print("i: ", i, " element: ", a[i])``

(8)查找某个元素

``# Find an element# Time complexity:O(N)index = a.index(2)# 1print(index)``

(9)数组排序

``# Sort an array# Time Complexity:O(NlogN)# From small to biga = [3,1,2]a.sort()# [1,2,3]print(a)# From big to smalla.sort(reverse=True)# [3,2,1]print(a)``