有什么岁月静好,不过是有人替你负重前行!哪

09 2021 档案

摘要:txt文件内容:就两个字 学习 f = open('date.txt','r') h = f.read() print(h) 执行结果为: 修改后的代码为: f = open('date.txt','r',encoding='utf-8') h = f.read() print(h) 执行后的结果为 阅读全文
posted @ 2021-09-26 10:53 longfei825 阅读(373) 评论(0) 推荐(0) 编辑
摘要:list = [1, 2, 3, 4, 5] ''.join(list) 结果即为:12345 ','.join(list) 结果即为:1,2,3,4,5 阅读全文
posted @ 2021-09-25 17:14 longfei825 阅读(27) 评论(0) 推荐(0) 编辑
摘要:两处错误一、你是用open打开一个文件,此时调用的是w写入模式,下面使用read是没有权限的,你得使用w+读写模式二、使用write写入一个字符s,但是此时并没有真正的写入,而是还存在与内存中。此时执行read读取的为空字符。需要执行a.close()以后,再使用a=open(“D://2.txt” 阅读全文
posted @ 2021-09-25 14:52 longfei825 阅读(366) 评论(0) 推荐(0) 编辑
摘要:首先看一下这个报错信息“TypeError: '***' object is not iterable”,意思是说:“类型错误:'***'对象不可迭代”。 阅读全文
posted @ 2021-09-25 11:47 longfei825 阅读(350) 评论(0) 推荐(0) 编辑
摘要:把这段英文报错翻译过来就是: 缩进错误: 期望一个缩进的块 阅读全文
posted @ 2021-09-25 11:44 longfei825 阅读(510) 评论(0) 推荐(0) 编辑
摘要:import re data = """我始终!@@##¥%…………&alkjdfsb1234\n 566667是中国人woaldsfkjzlkcjxv123*())<> """ # 匹配所有汉字 print(re.findall('[\u4e00-\u9fa5]', data)) # 匹配所有单字 阅读全文
posted @ 2021-09-25 10:35 longfei825 阅读(660) 评论(0) 推荐(0) 编辑
摘要:看懂下面的例子,你就会二进制转中文了! name = '中国万岁' print(name) #执行结果为:中国万岁 a = name.encode() print(a) #执行结果为:b'\xe4\xb8\xad\xe5\x9b\xbd\xe4\xb8\x87\xe5\xb2\x81' c = a. 阅读全文
posted @ 2021-09-24 17:07 longfei825 阅读(570) 评论(0) 推荐(0) 编辑
摘要:str( )是python自带函数,是python保留的关键字,定义变量时应该避免使用str作为变量名如果在使用str( )函数之前已经定义过str变量,则会出现TypeError: ‘str’ object is not callable这个报错 阅读全文
posted @ 2021-09-24 16:19 longfei825 阅读(641) 评论(0) 推荐(0) 编辑
摘要:str = '\xe5\xae\x9d\xe9\xb8\xa1\xe5\xb8\x82\' print (str(s,'utf8')) 上面代码执行报错如下: SyntaxError: EOL while scanning string literal google一下,这个异常造成的原因是字符串, 阅读全文
posted @ 2021-09-24 16:08 longfei825 阅读(1284) 评论(0) 推荐(0) 编辑
摘要:原因:写入的文件内容不正确,应处理为字符串 >>> import os >>> os.makedirs(time_year+"\\"+time_month+"\\"+time_day)#其中的time_year、time_month、time_day都是有赋值的变量 >>> os.chdir(tim 阅读全文
posted @ 2021-09-24 16:03 longfei825 阅读(622) 评论(0) 推荐(0) 编辑
摘要:import random def v_code(): code ='' for i in range(4): add = random.choice([random.randrange(10),chr(random.randrange(65,91))]) code+=str(add) print( 阅读全文
posted @ 2021-09-15 16:23 longfei825 阅读(78) 评论(0) 推荐(0) 编辑
摘要:著名的斐波拉契数列(Fibonacci),除第一个和第二个数外,任意一个数都可由前两个数相加得到: 1, 1, 2, 3, 5, 8, 13, 21, 34, ... 斐波拉契数列用列表生成式写不出来,但是,用函数把它打印出来却很容易: def fib(max): a,b,c = 0,1,1 whi 阅读全文
posted @ 2021-09-14 17:44 longfei825 阅读(130) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示