python中不可变集合

python中不可变集合,第1张

概述 1、>>>a={1,2,3}>>>a{1,2,3}>>>type(a)<class'set'>>>>a.add(4)>>>a{1,2,3,4}>>>b=frozenset({1,2,3})##不可变集合>>>bfrozenset({1,2,3})>>>t

 

1、

>>> a = {1,2,3}>>> a{1, 2, 3}>>> type(a)<class 'set'>>>> a.add(4)>>> a{1, 2, 3, 4}>>> b = froZenset({1,2,3})    ## 不可变集合>>> bfroZenset({1, 2, 3})>>> type(b)<class 'froZenset'>>>> b.add(4)Traceback (most recent call last):  file "<pyshell#845>", line 1, in <module>    b.add(4)AttributeError: 'froZenset' object has no attribute 'add'>>> c = froZenset(a)     ## 不可变集合>>> cfroZenset({1, 2, 3, 4})>>> c.add(4)Traceback (most recent call last):  file "<pyshell#848>", line 1, in <module>    c.add(4)AttributeError: 'froZenset' object has no attribute 'add'

 

总结

以上是内存溢出为你收集整理的python中不可变集合全部内容,希望文章能够帮你解决python中不可变集合所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1189088.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存