#崔鑫阳 2019.2.26
# legb
# l->local 局部
# e->enclose 嵌套区域
# g->globals 全局
# b->buit_in 内置
legb
l->local 局部
e->enclose 嵌套区域
g->global quanju
b->buit_in neizhi
a=100
b=2
c=1
def i():
b=100
def j():
c=200
print(c)
print(b)
print(a)
print(max)
j()
i()
dic={
"001":{"name":"韩愈" ,"No.":"1","年代":"唐"},
"002":{"name":"柳宗元","No.":"2","年代":"唐"},
"003":{"name":"骆宾王","No.":"3","年代":"宋"},
"004":{"name":"欧阳修","No.":"4","年代":"宋"},
"005":{"name":"苏轼" ,"No.":"5","年代":"宋"}
}
def zengjia(k,d):
dic[k]=d
k=input("输入编号")
d=input("输入字典")
for i in dic:
if i==k:
print("congfu")
break
else:
zengjia(k,d)
print(dic)
def zj(k,d):
dic[k]=d
k=input("shuru")
d=input("shuru")
for i in dic:
if i==k:
print("congfu")
break
else:
zj(k,d)
print(dic)
def zj(k,d):
dic[k]=d
k=input("shuru")
d=input("shuru")
for i in dic:
if i==k:
print("congfu")
break
else:
zj(k,d)
print(dic)
w=open("d:\\a.txt",'w')#以只写的方式打开d文件下的a.txt文件
w.write("I love U")#输入文字
w.close()#关闭
w=open("d:\\a.txt",'w')
w.write("i o u")
w.close()
w=open("d:\\a.txt",'w')
w.write("uoi")
w.close()
w=open("a.txt",'a+')#以只写的方式打开d文件下的a.txt文件
w.write("I love U")#输入文字
w.seek(0)
a=w.read(8)
print(a)
w.close()#关闭
w=open("a.txt",'w+')
w.write("x,x,x")
w.seek(0)
x=w.read(4)
print(x)
w.close()
w=open("a.txt",'r')#以只读的方式打开d文件下的a.txt文件
content=w.read()
print(content)
w.close()#关闭
w=open("a.txt",'r')
content=w.read()
print(content)
w.close()
w=open("a.txt",'r')
content=w.read()
print(content)
w.close()
w=open("a.txt",'r',encoding='utf-8')#以只读的方式打开d文件下的a.txt文件
content=w.readlines()
print(content)
w.close()#关闭
w=open("a.txt",'a',encoding='utf-8')#以只写的方式打开d文件下的a.txt文件
w.write("\n")
w.write("\n")
w.write("打扰了\n")#输入文字
w.write("\n")
w.write("gun")
w.close()#关闭
w=open("a.txt",'r',encoding='utf-8')
content=w.read()#中文2-3个字符位
# print(content)
# print(w.tell())
w.seek(2,0)#第一个为偏移量,第二个为偏移方向,0是从头,1是当前,2是结尾
print(content)
w.close()
w=open("b.txt",'w',encoding='utf-8')
w.close()
import os
os.rename("c.txt","cc.txt")
import os
os.remove("b.txt")
os.mkdir("lala",0x777)
print(os.getcwd())#显示目录的路径
os.rmdir('lala')#删除目录
print(os.path.exists("lala"))
print(os.path.exists("c.txt"))
os.removedirs(("a//b//c"))
def x(n):
for i in range(n):
yield i
a=x(1000)
print(next(a))
print(next(a))
print(next(a))
print(next(a))
def x(n):
for i in range(n):
yield i
a=x(1000)
print(next(a))
print(next(a))
print(next(a))
print(next(a))
def x(n):
for i in range(n):
yield i
a=x(1000)
print(next(a))
print(next(a))
print(next(a))
def x(n):
for i in range(n):
yield i
a=x(1000)
print(next(a))
print(next(a))
print(next(a))
print(next(a))
import time
def sj(x):
def neibu():
start=time.time()
x()
end=time.time()
print(end-start)
return neibu
@sj
def i():
for l in range(123):
print('1,2,3',end='')
i()
import time
def sj(x):
def niebu():
start=time.time()
x()
end=time.time()
print()
print(end-start)
return niebu
@sj
def i():
print('1,2,3',end='')
i()
def xu(name):
def nb(cs):
print("**************************")
name(cs)
print("**************************")
return nb
def dd(name):
def nb(cs):
print("——%¥#¥%……%¥#¥%——")
name(cs)
print("——%¥#¥%……%¥#¥%——")
return nb
@dd
@xu
def y(name):
print(' ',name,"牛批")
y("GOD C")
def x(name):
def nb(c):
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
name(c)
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
return nb
def d(name):
def nb(c):
print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
name(c)
print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
return nb
@d
@x
def i(name):
print(" ",name)
i("6666666666")
def x(name):
def nb(c):
print(">>>>>>>>>>>>>>>")
name(c)
print(">>>>>>>>>>>>>>>")
return nb
def t(name):
def nb(c):
print(">>>>>>>>>>>>>>>")
name(c)
print(">>>>>>>>>>>>>>>")
return nb
@t
@x
def i(name):
print(" ",name)
i("9292929")
def x(b):
a=2
def nb (c):
d=a*b+c
return d
return nb
t=x(3)
print(t(5))
print(t(7))
def x(b):
a=2
def nb(c):
d=a*b+c
return d
return nb
t=x(3)
print(t(5))
def x(b):
a=2
def nb(c):
d=a*b+c
return d
return nb
t=x(3)
print(t(5))
python学习第8天
最新推荐文章于 2019-04-25 20:49:12 发布