Describe
The Remove () function is used to delete the first occurrence of a value in a list.
Grammar
List. Remove(obj) can only delete one element at a time.
Del list[] deletes more than one element at a time.
Parameters
return value
The method does not return a value but removes the first occurrence of one of two values.
Example 01
How to use the Remove ():
1 #Author: junce Liu2City = ["Hangzhou","Suzhou","Guangzhou","Suzhou","Tongzhou","Yangzhou"]3 print (city)4City.remove ("Yangzhou") # Delete the specified element "Yangzhou"5 print (city)6 7 The output results are as follows:8['Hangzhou','Suzhou','Guangzhou','Suzhou','Tongzhou',' Yangzhou ']9['Hangzhou','Suzhou','Guangzhou','Suzhou','Tongzhou']
Example 02
How to Use del list[]:
1 #Author: junce Liu2City = ["Hangzhou","Suzhou","Guangzhou","Suzhou","Tongzhou","Yangzhou"]3 print (city)4Del city[4:6] # Delete index 4:6 element for" Tongzhou", "Yangzhou"
5 print (city)6 7 The output results are as follows:8['Hangzhou','Suzhou','Guangzhou','Suzhou','Tongzhou','Yangzhou'] 9['Hangzhou','Suzhou','Guangzhou','Suzhou']
List Remove () method