Python del 關鍵字
定義和用法
del 用于刪除對象。在 Python,一切都是對象,因此 del 關鍵字可用于刪除變量、列表或列表片段等。
更多實例
實例
刪除變量:
x = "hello" del x print(x)
實例
刪除列表中的首個項目:
x = ["apple", "banana", "cherry"] del x[0] print(x)
del 用于刪除對象。在 Python,一切都是對象,因此 del 關鍵字可用于刪除變量、列表或列表片段等。
刪除變量:
x = "hello" del x print(x)
刪除列表中的首個項目:
x = ["apple", "banana", "cherry"] del x[0] print(x)