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

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:

主站蜘蛛池模板: 泸州市| 汉中市| 德昌县| 平邑县| 三都| 仙居县| 湘乡市| 鹤山市| 鄂温| 武安市| 枣阳市| 中江县| 宝丰县| 定安县| 潼南县| 高邑县| 谢通门县| 类乌齐县| 溆浦县| 建昌县| 灵川县| 呼伦贝尔市| 灵台县| 金山区| 马尔康县| 岫岩| 九龙县| 东宁县| 淮北市| 色达县| 乌苏市| 湖北省| 彝良县| 三亚市| 赤壁市| 石台县| 大同市| 扎赉特旗| 崇文区| 乌鲁木齐市| 凤山市|