In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to delete elements from lists in python. The introduction in this article is very detailed and has certain reference value. Interested friends must read it!
#remove: remove elements by their values list1.remove ('milk ')print(list1)#result: [' ham sausage','bread',' cola','instant noodle']# remove: remove elements by their values list1.remove ('milk ')print(list1)
#Result: ['ham sausage',' bread','cola',' instant noodle ']
# pop: Delete elements by index, if no index is filled, the last one will be deleted by default. pop can return deleted elements to list1.pop(-2)print(list1.pop())print(list1)
#Result:
#Instant noodles
# ['ham sausage',' bread','milk']
# del: Delete a single element (same function as pop), delete multiple elements, delete the entire list from memory del list1[-2]print(list1)#Result: ['ham sausage',' bread','milk',' instant noodle '] del list1[1:3]print(list1)#Result: [' ham sausage','cola',' instant noodle '] #Delete all variables with contents from memory del list 1 #clear: Empty list, list is still there, but every content in it print(list1.clear())print(list1)
#Result:
# None
# []
The above is "how to delete elements from lists in python". Thank you for reading it! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.