list使用
lists = ["胡勇", "卢雯婷", 1]
print("----------添加元素的方法------------")
lists.append("中国地质大学")
lists.insert(2, "大学")
subLists = ["天津科技大学", "滨海"]
lists.extend(subLists)
print(lists)
print("----------查找元素-----------------")
if "胡勇" in lists:
print(True)
print(lists.index("胡勇"))
print(lists.count("胡勇"))
print("----------删除元素---------------")
print(lists.pop())
print(lists.pop(0))
print(lists.remove("卢雯婷"))
print(lists.clear())
print("----------列表的排序---------------")
a = [1, 4, 2, 3]
a.reverse()
print(a)
a.sort()
print(a)
a.sort(reverse=True)
print(a)
words = ['hello', '', 'good', 'hi', '', 'yes', '', 'no']
lst1 = ['12 ', ' 13 ', ' 14', ' 15 ']
lst2 = [x.strip() for x in lst1]
print(lst2)
print("----------列表的循环遍历------------")
namesList = ['xiaoWang', 'xiaoZhang', 'xiaoHua']
length = len(namesList)
i = 0
while i < length:
print(namesList[i])
i += 1
for name in namesList:
print(name)
print("----------列表的拷贝------------")
import copy
arrays = [1, 2, 3, 4]
copyArrays1 = arrays.copy()
copyArrays2 = copy.copy(arrays)
copyArrays3 = arrays[::]
print(id(arrays))
print(id(copyArrays1))
print(id(copyArrays2))
print(id(copyArrays3))