官术网_书友最值得收藏!

Immutable sets

Python has an immutable set type called frozenset. It works pretty much exactly like set apart from not allowing methods or operations that change values such as the add() or clear() methods. There are several ways that this immutability can be useful. For example, since normal sets are mutable and therefore not hashable, they cannot be used as members of other sets. The frozenset, on the other hand, is immutable and therefore able to be used as a member of a set:

Also the immutable property of frozenset means we can use it for a key to a dictionary, for example:

主站蜘蛛池模板: 辽源市| 友谊县| 腾冲县| 德兴市| 安远县| 安陆市| 泸州市| 垣曲县| 淳化县| 黎平县| 宜阳县| 启东市| 霍林郭勒市| 海宁市| 讷河市| 株洲市| 平度市| 大同县| 衡南县| 如东县| 荥经县| 盐山县| 马鞍山市| 岳池县| 邢台县| 芜湖市| 安仁县| 英吉沙县| 宁阳县| 景泰县| 巴南区| 临城县| 广灵县| 射阳县| 六安市| 东明县| 武陟县| 汝州市| 惠安县| 山东省| 克山县|