- 博客(17)
- 收藏
- 关注
原创 OS模块全解
OS模块 import os os.getcwd()获取当前路径 C:\\Users\\Administrator os.chdir("C:\\Users")改变路径 os.getcwd() C:\\Users os.chdir(r"C:\\Users\Administrator")返回路径 os.getcwd() C:\\Users\\Administrator os.curdir返回当前目录 . os.pardir返上级前目录 .. os.makedirs(r"C:\a\b\c\d")用递归的方法生.
2021-12-16 15:08:18
182
原创 json序列化
输入: {"name": "lilin", "age": 22} import pickle #只能在python本语言中用 def sayhi(name): print("hello",name) info= { "name":"lilin", "age":22, "func":sayhi } f=open("test.test","wb") print() f.write(pickle.dumps(info)) f.close() 输出: __��sayh
2021-11-25 09:15:13
563
原创 json反序列化
import json f = open("test.test","r") data = json.loads( f.read())#将字典转换为字符串进行打印 print(data["age"]) f.close() 输出: 22 输入: import pickle def sayhi(name): print("hello",name) print("hello2", name) f=open("test.test","rb") data = pickle..
2021-11-25 09:11:47
162
原创 斐波那契数列的应用
def fib(max): n,a,b=0,0,1 while n < max: #print(b) yield b a,b=b,a+b n=n+1 return "done" f=fib(10) g=fib(6) while True: try: x=next(g) print("g",x) except StopIteration as e: #检查捕捉错误.
2021-11-11 14:24:48
352
原创 嵌套函数的案例
输入: import time user,passwd="lilin","abc123" def auth(auth_type): print("auth func:",auth_type) def outer_wrapper(func): def wrapper(*args,**kwargs): print("wrapper func args:",*args,**kwargs) if auth_type=="loc...
2021-11-09 16:56:34
230
原创 装饰器的应用
import time def timer(func): def deco(): start_time=time.time() func() stop_time=time.time() print("the func run time is %s"%(stop_time-start_time)) return deco @timer def test1(): time.sleep(3) print("in t.
2021-11-02 09:18:40
79
原创 高阶函数的定义
#定义:把一个函数名当做实参传给另一个函数(在不修改比装饰函数源代码的情况下为其添加功能,返回值中包含函数名),返回值中包含函数名,不修改函数的调用方式。
2021-11-02 09:17:47
188
原创 进度条的操作代码
import sys import time for i in range(20): sys.stdout.write(">") sys.stdout.flush() time.sleep(0.1)
2021-10-26 15:36:02
222
原创 全局变量与局部变量
def test(x,*args): print(x) print(args) test(1,2,3,4,5,6,7) 总结:参数组主要用于传输
2021-10-25 16:47:39
89
原创 参数组的应用
def test(name,age=19,*args,**kwargs): print(name) print(args) print(kwargs) # print(kwargs["name"]) # print(kwargs["age"]) test("lilin",age=26,hobby="tesla",sex="f") 位置参数写在关键字参数前面
2021-10-25 16:05:36
100
原创 实参与形参
def test(x,y,z): print(x) print(y) print(z) test(2,z=3,y=8) 总结:关键参数不能放在位置参数的前面
2021-10-25 11:16:22
88
原创 函数的返回值
def test1(): print("in the test1") def test2(): print("in the test2") return 0 def test3(): print("in the test3") return 1,"hello",["alex","huge"],{"name":"linzaimu"} x = test1() y = test2() z = test3() print(x) print(y) print(z) #.
2021-10-25 10:26:16
88
原创 函数的好处
#总结函数的好处:代码重用,保持一致性,可扩展性 import time def logger(): time_format = "%Y-%m-%d %X" time_current = time.strftime(time_format) with open("a.txt","a+") as f: f.write("%s end action\n" %time_current) def test1(): print("in the test1") l...
2021-10-21 11:07:11
577
原创 三级菜单实例
data = { '北京':{ "昌平":{ "沙河":["oldboy","test"], "天通苑":["链家地产","我爱我家"] }, "朝阳":{ "望京":["奔驰","陌陌"], "国贸":{"CICC","HP"}, "东直门":{"Advent","飞信"}, }, "海淀":{},.
2021-08-30 17:16:05
98
原创 字典实例解析
info = { 'stu1101':"TengLan Wu", 'stu1102':"LongZe Luola", 'stu1103':"XiaoZe Maliya", } print(info) print(info['stu1101']) info["stu1101"]="武藤兰" #修改 info["stu1104"]="Cangjingkong" #添加 del info["stu1101"] #删除 info.popitem() #随便删除一个 print(in.
2021-08-26 14:01:02
275
原创 解释型语言和编译型语言
计算机是不能识别高级语言的,所以当我们运行一个高级语言程序的时候,就需要一个“翻译机”来从事吧高级语言变成能读懂的机器语言的过程,这个过程分成两类,一种是编译,另一种是解释。 编译型语言在程序执行之前,先会通过编译器对程序执行一个编译的过程,把程序转变为机器语言,运行时就不需要翻译,而直接执行就行了,最典型的例子就是C语言。 解释型语言就没有这个编译的过程,而是咋子程序运行的时候,通过解释器对程序逐行作出解释,然后直接运行,最典型的例子就是Ruby。 通过以上的例子,我们可以来总结一下解释型语言的优缺
2021-08-24 09:12:13
111
原创 whlie 循环
#进击小艾 count=0 while count<3: age_of_lilin=26 guess_age=int(input("guess age:")) if guess_age==age_of_lilin: print("yes, you got it.") break elif guess_age > age_of_lilin: print("you can smaller.") else: .
2021-08-19 13:45:40
269
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅