In python, you can use the "del()" function to delete one or several consecutive elements. This function is used to delete elements. Its syntax is "del $data", and its parameter $data represents the data to be deleted. .
Usage:
-------del is used for list operations to delete one or several consecutive elements.
# Define a list
>>> a = [1,2,3,4]
>>> a
[1,2,3,4]
##>>> del a[0] # Delete the 0th element>>> a[2,3,4]>>> del a[1:3] # Delete elements starting from the 1st element to the 3rd element. >>> a[2]#Delete elements including the head but not the tail>>> del a #Delete the entire list>>> aTraceback (most recent call last): File "Python Tutorial"
The above is the detailed content of Detailed explanation of the usage of del function in python. For more information, please follow other related articles on the PHP Chinese website!