python代码如下:
# python中set函数基本用法示例(编程之家 jb51.cc整理)
s = set()
s = {11,22,33,44} #注意在创建空集合的时候只能使用s=set(),因为s={}创建的是空字典
a=set('boy')
b=set(['y','b','o','o'])
c=set({"k1":'v1','k2':'v2'})
d={'k1','k2','k2'}
e={('k1','k2')}
print(a,type(a))
print(b,type(b))
print(c,type(c))
print(d,type(d))
print(e,type(e))
OUTPUT:
{'o','y'}
{'o','y'}
{'k1','k2'}
{'k1','k2'}
{('k1','k2')}
# 来自jb51.cc
原文链接:https://www.f2er.com/python/527351.html