10_集合


创建集合
# 集合,无序
# 创建集合
# {'Love', 'Python'}
print({"Love", "Python"})
# {'o', 'h', 't', 'n', 'P', 'y'}
print({s for s in "Python"})
# {'o', 'h', 't', 'n', 'P', 'y'}
print(set("Python"))
通过集合判断是否有相同元素
a = [1, 2, 3, 1, 1, 5]
# 结果返回False,说明集合之中存在相同的元素
print(len(a) == len(set(a)))

 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/278975.html

(0)
上一篇 2022年8月5日 01:27
下一篇 2022年8月5日 02:03

相关推荐

发表回复

登录后才能评论