dir(frozenset)
来查看 frozenset 集合支持的方法:
>>> dir(frozenset)
['copy', 'difference', 'intersection', 'isdisjoint', 'issubset', 'issuperset', 'symmetric_difference', 'union']
s = {'Python', 'C', 'C++'} fs = frozenset(['Java', 'Shell']) s_sub = {'PHP', 'C#'} #向set集合中添加frozenset s.add(fs) print('s =', s) #向为set集合添加子set集合 s.add(s_sub) print('s =', s)运行结果:
s = {'Python', frozenset({'Java', 'Shell'}), 'C', 'C++'}
Traceback (most recent call last):
File "C:\Users\mozhiyan\Desktop\demo.py", line 11, in <module>
s.add(s_sub)
TypeError: unhashable type: 'set'
本文链接:http://task.lmcjl.com/news/9327.html