一、集合及其运算
list_1=set([1,2,3,4,5])
lise_2-set([2,3,4,5,6,7,8])
#交集:intersection
#并集:union
#差集:difference
decard:#有就去除,没有就不操作
二、文件的读写修改
with open(‘文件名’,‘要做的操作(r读,w建立一个新文件写不,a在原文件末添加但是不可读),encoding=‘utf-8’) as f : ‘’’…’’’
r+:读完写
w+:写完读
a+:添加完读
print(f.tell())#打印光标位置
f.seek()#将光标移到某一位置//两个一起使用
print(f.readline())#读一行
文件的特定内容修改(在一个新的文件生成)
利用循环:for line in f :
if ‘…’ in line:
line=line.replace(’…’)
f_new.write(line)
三、进度条程序:
import sys,time
for i in range(30):
sys.stdout.write(’#’)
sys.stdout.flush()
time.sleep(0.2)
四、编码的转换
utf-8<----->unicode<----->gbk
先decode再encode
五、函数
def test (a,b)
print(a)
print(b)
执行:test(2,b=3)
**变量名赋值不能在位置赋值前面
返回值包括数字、字符串、列表、字典
函数可以调用函数
变量可以是数字、字符串、列表、字典
利用 *args调用列表,输出转换称元组
利用 **kwargs调用字典,输出为字典
六、递归
函数调用函数自己/
e.g.:
def calo(n):
print(n)
if int(n/2)>0:
return calo(int(n/2))
calo(10)