Python-31 - 陣列介紹 - list 刪除、清除資料 del、clear()

 list 刪除、清除資料 del、clear()

 

list 刪除、清除資料 del、clear()

#del 刪除第幾個元素
M2 = ["A","B","C","D","E"]
del M2[2]
print(M2)
#['A', 'B', 'D', 'E']

Member_id = list(("MBA","MBB","MBC","MBD"))
del Member_id[0]
print(Member_id)
#['MBB', 'MBC', 'MBD']


#clear()刪除所有元素
M2 = ["A","B","C","D","E"]
M2.clear()
print(M2)
#[]

看看效果

 

Yiru@Studio - 關於我 - 意如