集合
s={1,2,3,4,5,6,7,8,9}
print(s)
s2 = set()
添加
s2.add(1)
print(s2)
去重
aba =[1,2,3,2,1,3,1,2,3]
print(set(aba))
print(list(aba))
print(list[set(aba)])
aaa ={'wangba','xiaoji','dada','xiaoxiao'}
bbb = {1,2,3,2,4,5,3,2,33,2,22,3,'xiaoxiao'}
长度
len(aba)
len(aaa)
'xiaoxiao' in aaa
并集
print(aaa|bbb)
print(aaa.union(bbb))
交集
print(aaa&bbb)
差集
print(aaa-bbb)
对称差集
print(aaa^bbb)
==
print(aaa==bbb)
<=
print(aaa<=bbb)
>=
print(aaa>=bbb)
<
print(aaa<bbb)
>
print(aaa>bbb)
s = set()
add 添加
s.add('wsad')
print(s)
remove 移除
s.remove('wsad')
print(s)
bbb = {1,2,3,2,4,5,3,2,33,2,22,3,'xiaoxiao'}
aaa ={'wangba','xiaoji','dada','xiaoxiao'}
print(aaa.difference(bbb))
bbb.discard(1)
print(bbb)
aaa.isdisjoint(bbb)
f =open(r'C:\Users\32758\Desktop\test.txt',encoding='utf-8')
print(f.read())
f.close()
f =open(r'D:\pyObject\pythonProject\学习\test.txt',encoding='utf-8')
print(f.readline())
print(f.readline())
print(f.readline())
print(f.readline())
f.close()
fw =open(r'D:\pyObject\pythonProject\学习\test.txt',mode='w',encoding='utf-8')
fw.write('hello 1 world\n')
fw.flush()
fw.close()
import sys
print(sys.path)
fr =open('学习/test.txt',mode='r',encoding='utf8')
text_data = fr.read()
print(text_data)
print(r'1\n2')
print(b'1\n2223441')
xie
with open('学习/test.txt','w',encoding='utf8') as fa:
fa.write('deep dark')
du
with open('学习/test.txt', 'r', encoding='utf8') as fr:
data = fr.read()
print(data)
with open('学习/test.txt','r',encoding='utf8') as fr:
print(fr.readable())
print(fr.writable())
指针
with open('学习/test.txt', 'r+', encoding='utf8') as frr:
frr.seek(0,0)
frr.write('大')
frr.flush()
print(frr.tell()) #光标位置 字节
print(frr.read(3)) #光标后字符数
frr.truncate() #截断
frr.flush()