python基础07
python基础07
昨日回顾:
小数据池:
int -5----->256
str 特殊字符,*数字20
ASCII:8位 1字节 表示1个字符
Unicode 32位 4个字节 表示一个字符
utf-8 1个英文 8位 1个字节
欧洲 16位 两个字节 表示一个字符
亚洲 24位 三个字节 表示一个字符
gbk 1个英文 8位 1个字节
亚洲 16位 两个字节 表示一个字符
s = 'alex'
b = s.encode('utf-8')
print(b)#b'alex'
1.基础数据类型汇总补充
str
int
list
bool
dict
2.集合set
3.深浅copy
查看关于这个所有的函数
'''
str int
'''
str
s = ' '
print(s.isspace())
list :
'''
lis = [11,22,33,44,55]
for i in lis:
del lis[lis.index(i)]
#int
'''
lis = [11,22,33,44,55]
for i in range(len(lis)):
del lis[i]
'''
list = [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'}
for i in dic:
print(i)
dic = {'k1':'v1','k2':'v2','a3':'v3'}
for i in dic:
if 'k' in i:
del dic[i]
dic = {'k1':'v1','k2':'v2','k3':'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)
#转化成bool值
#0 ‘’ [] () {} set()
#元祖
tu1 = (1)
tu =(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))
print(set)
set2 = [1,2,3,[2,3],{'name':'alex'}]
print(set1)
print(set2)
set1 = {'alex','wusir','ritian','egon','barry'}
#add
set1.add('女神')
print(set1)
set1 = {'alex','wusir','ritian','egon','barry','barry'}
#add
set1.add('女神')
print(set1)
set1.update('abc')
print(set1)
#删除
set1.pop()#随机删除
print(set1)
#删除
set1.pop()#随机删除
print(set)
#set1.pop()#随机删除
#print(set1.pop())#有返回值
#print(set1)
set1.remove('alex')#按元素
print(set1)
set1.clear()
print(set1)
#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}
set1 = {1,2,3,4,5}
set2 = {4,5,6,7,8}
set3 = set1&set2
print(set3)#{4,5}
print(set1.intersection(set2))#{4,5}
set1 = {1,2,3,4,5}
set2 = {4,5,6,7,8}
print(set1|set2)#{1,2,3,4,5,6,7,8}
print(set2.union(set1))#{1,2,3,4,5,6,7,8}
set1 = {1,2,3,4,5}
set2 = {4,5,6,7,8}
print(set1^set2)#{1,2,3,6,7,8}
print(set1.symmetric_difference(set2))
set1 = {1,2,3,4,5}
set2 = {4,5,6,7,8}
print(set1 -set2)
set1 = {1,2,3}
set2 = {1,2,3,4,5,6}
print(set1<set2)
print(set.issubset(set2))
li = [1,2,33,33,2,1,4,5,6,6]
set1 = set(li)
print(set1)
s = frozenset('barry')
print(s,type(s))
#s1 = {1,2,3}
print(s1,type(s1))
s =frozenset('barry')
print(s,type(s))
s =frozenset('barry')
print(s,type(s))
for i in s:
print(i)
s = frozenset('barry')
print(s,type(s))
for i in s:
print(i)