摘要: #实参有位置参数,和关键字参数,关键字参数后面不能有位置参数。def test(x,y,z): print(x) print(y) print(z)test(2,z=2,y=6)test(2,3,4) 阅读全文
posted @ 2020-05-13 10:50 Carol7258 阅读(138) 评论(0) 推荐(0)
摘要: #不管怎么转变,ASC, utf-8, gbk,都要先转成unicode,再转到你想要的编码格式s = "你好"s_gbk = s.encode("gbk")print(s_gbk)print(s.encode())gbk_to_utf8 = s_gbk.decode("gbk").encode(" 阅读全文
posted @ 2020-05-09 14:16 Carol7258 阅读(131) 评论(0) 推荐(0)
摘要: # open w, 会覆盖文件,一般修改文件,我们会新建一个加判断修改写入新文件。不在旧文件上操作。f=open("yesterday",'r',encoding="utf-8")f_new = open("yesterday.bak",'w',encoding="utf-8")for line i 阅读全文
posted @ 2020-05-09 10:27 Carol7258 阅读(188) 评论(0) 推荐(0)
摘要: '''# R+ read and writef = open("yesterday",'r+',encoding="utf-8")print(f.readline())print(f.tell())f.write(" first line ")print(f.readlines())'''#w+ w 阅读全文
posted @ 2020-05-08 20:51 Carol7258 阅读(94) 评论(0) 推荐(0)
摘要: import sys,timefor i in range(50): sys.stdout.write("#") sys.stdout.flush()# flash the data from memory time.sleep(0.1) 阅读全文
posted @ 2020-05-08 20:50 Carol7258 阅读(95) 评论(0) 推荐(0)
摘要: '''f = open("yesterday1",'a',encoding = "utf-8")# a 追加,R只读,w覆盖写‘’覆盖#data = f.read()#print(data)f.write("我爱北极.\n")f.write("l love you")f.close()'''f = 阅读全文
posted @ 2020-05-08 19:51 Carol7258 阅读(102) 评论(0) 推荐(0)
摘要: # info = {# 'stu1':'Ivy',# 'stu2':'carol',# 'stu3':'Green'# }# b = {# 'stu1': 'Will',# 1:3,# 2:5# }# info.update(b)#合并加更改# iterms#print(info.items())# 阅读全文
posted @ 2020-05-05 08:12 Carol7258 阅读(142) 评论(0) 推荐(0)
摘要: #输出10X5次for i in range(0,10): print(" ",i) for j in range(0,10): if j < 5: print("loop:", j) else: break 阅读全文
posted @ 2020-05-01 19:08 Carol7258 阅读(108) 评论(0) 推荐(0)
摘要: age_of_oldboy = 56for i in range(3): age = int(input("Input the age: ")) if age==age_of_oldboy: print("You got it.") break elif age > age_of_oldboy: p 阅读全文
posted @ 2020-05-01 18:59 Carol7258 阅读(98) 评论(0) 推荐(0)
摘要: age_of_oldboy = 56count = 0while count <3: age = int(input("Input the age: ")) if age==age_of_oldboy: print("You got it.") break elif age > age_of_old 阅读全文
posted @ 2020-05-01 18:57 Carol7258 阅读(128) 评论(0) 推荐(0)