编程语言
首页 > 编程语言> > python第七课

python第七课

作者:互联网

#str int
#str
# s=''
# print(s.isspace())
#list:
# lis=[11,22,33,44,55]
# for i in range(len(lis)):
# print(i)
# del lis[i]
# print(lis)
dic={'k1':'v1','k2':'v2','a3':'v3'}
dic1={}
# for i in dic:
# if 'k' not in i:
# dic1.setdefault(i,dic[i])
# dic=dic1
# print(dic)
# l=[]
# for i in dic:
# if 'k' in i:
# l.append(i)
# for i in l:
# del dic[i]
# print(dic)
#转化成boo值
#0 '' [] () {} set()
#元祖 如果元祖里面只有一个元素且不加,那此元素是什么类型就是什么类型.
# tu1=(1)
# tu2=(1,)
# print(tu1,type(tu1))
# print(tu2,type(tu2))
# tu1=([1])
# tu2=([1],)
# print(tu1,type(tu1))
# print(tu2,type(tu2))

#集合:可变的数据类型,他里面的元素必须是不可变的数据类型,无序,不重复,
# set1=set({1,2,3})
# set2={1,2,3,[2,3],{'name':'alex'}} #错的
# print(set1)
# print(set2)
set1={'alex','wusir','ritian','egon','barry'}
#add
#set1.add('女神')
# print(set1)
#update
# set1.update('abc')
# print(set1)
#删除
# set1.pop()#随机删除
# print(set1.pop())#有返回值
# print(set1)
# set1.remove('alex')#按元素删除
# print(set1)

#{}_set()清空集合
# set1.clear()
# print(set1)#set

# del set1
# # print(set1)
# for i in set1:
# print(i)
#交集和并集,反交集
# set1={1,2,3,4,5}
# set2={4,5,6,7,8}
# print(set1&set2)#交集 {4,5}
# print(set1.intersection(set2))#交集{4,5}
# print(set1|set2)#并集12345678
# print(set2.union(set1))#并集12345678
# print(set1-set2)#差集{123}
# print(set1.difference(set2))#差集123}
#子集与超集
# set1={1,2,3}
# set2={1,2,3,4,5,6}
# print(set2 > set1)
# print(set2.issuperset(set1))#这两个相同,都是说明set2是set1超集
# print(set1<set2)
# print(set1.issubset(set2))#这两个相同,都是说明set1是set2子集
#去重
# li=[1,2,33,33,2,1,4,5,6,6]
# set1=set(li)
# # print(set1)
# li=list(set1)
# print(li)
# s1={1,2,3}
# print(s1,type(s1))
s=frozenset('barry')
print(s,type(s))
for i in s:
print(i)

标签:python,tu1,tu2,dic,第七课,set1,set2,print
来源: https://www.cnblogs.com/huangjianfeng/p/11220488.html