In order to remove the first element of the array, the index that must be considered is 0 as the index of the first element in any array is always 0. As like removing the last element from an array, removing the first element from the array can be processed using the same techniques.
讓我們將這些技術應用於刪除陣列的第一個元素。現在,我們將逐一討論用於從陣列中刪除第一個元素的方法和關鍵字。
The method pop() is used to delete the elements of the arrays, lists, etc in Python programming language. This mechanism works by using the index of the element which must be removed or deleted from the array.
##所以,要刪除陣列的第一個元素,請考慮索引0。元素只是從數組中彈出並被刪除。下面描述了「pop()」方法的語法。讓我們使用這個方法刪除陣列的第一個元素。文法
arr.pop(0)
arr = [" Hello ", " Programming ", " Python ", " World ", " Delete ", " Element "] first_index = 0 print(" The elements of the array before deletion: ") print(arr) print(" The elements of the array after deletion: ") arr.pop(first_index) print(arr)
The elements of the array before deletion: [' Hello ', ' Programming ', ' Python ', ' World ', ' Delete ', ' Element '] The elements of the array after deletion: [' Programming ', ' Python ', ' World ', ' Delete ', ' Element ']
#
del arr[first_index]
arr = [" Hello ", " Programming ", " Python ", " World ", " Delete ", " Element "] first_index = 0 print(" The elements of the array before deletion: ") print(arr) print(" The elements of the array after deletion: ") del arr[first_index] print(arr)
The elements of the array before deletion: [' Hello ', ' Programming ', ' Python ', ' World ', ' Delete ', ' Element '] The elements of the array after deletion: [' Programming ', ' Python ', ' World ', ' Delete ', ' Element ']
文法
variable = n.delete(arr, first_index)
import numpy as n arr = [" Hello ", " Programming ", " Python ", " World ", " Delete ", " Element "] variable = n.array(arr) first_index = 0 print(" The elements of the array before deletion: ") print(variable) variable = n.delete(arr, first_index) print(" The elements of the array after deletion: ") print(variable)
The elements of the array before deletion: [' Hello ', ' Programming ', ' Python ', ' World ', ' Delete ', ' Element '] The elements of the array after deletion: [' Programming ', ' Python ', ' World ', ' Delete ', ' Element ']
以上是Python程式刪除數組中的第一個元素的詳細內容。更多資訊請關注PHP中文網其他相關文章!