鱼C论坛

 找回密码
 立即注册
查看: 3162|回复: 0

[技术交流] set的回顾

[复制链接]
发表于 2020-10-21 13:15:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
set集合具有唯一性,无序性,所以没有索引index
frozenset()用来限制集合的修改
  1. set1 = frozenset([1, 2, 3, 5])
  2. set2 = {1, 3, 2, 5}
  3. print(set1 == set2)
  4. # 下面则不可创建集合
  5. try:
  6.     set3 = {[1, 2, 3, 5]}
  7. except Exception as e:
  8.     print(e)
  9. try:
  10.     set1.add(4)  # set1不可变更
  11. except Exception as e1:
  12.     print(e1)
  13. set2.add(8)
  14. set2.remove(3)
  15. print(set2)
  16. set4 = {1, 1.0}
  17. print(set4)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-28 15:54

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表