租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

discard在python中的用法是什么,python_card

发布时间:2024-07-12 04:17:26

discard在python中的用法是甚么

在Python中,discardset对象的一个方法,用于删除集合中的指定元素。如果集合中存在要删除的元素,则该元素会被删除;如果集合中不存在要删除的元素,则该方法不会引发毛病,而是静默地完成操作。示例以下:

s = {1, 2, 3, 4}

s.discard(2)
print(s)  # Output: {1, 3, 4}

s.discard(5)
print(s)  # Output: {1, 3, 4}

tiktok粉丝购买:https://www.smmfensi.com/