[Python] python从字典删除元素的方法 →→→→→进入此内容的聊天室

来自 , 2021-04-26, 写在 Python, 查看 148 次.
URL http://www.code666.cn/view/23e582ad
  1. # Create an empty dictionary
  2. d = {}
  3.  
  4. # Add an item
  5. d["name"] = "Fido"
  6. assert d.has_key("name")
  7.  
  8. # Delete the item
  9. del d["name"]
  10. assert not d.has_key("name")
  11.  
  12. # Add a couple of items
  13. d["name"] = "Fido"
  14. d["type"] = "Dog"
  15. assert len(d) == 2
  16.  
  17. # Remove all items
  18. d.clear()
  19. assert len(d) == 0
  20. #//python/8027

回复 "python从字典删除元素的方法"

这儿你可以回复上面这条便签

captcha