摘要: 文件属性 f=open('poem8','w',encoding='utf8')# 用非负整型数来表示当前操作对象的文件号print(f.fileno())# 判断操作对象是否为终端,返回 True / Falseprint(f.isatty())# 判断操作对象是否可读,返回 True / Fal 阅读全文
posted @ 2020-03-12 15:07 wtzxxy 阅读(79) 评论(0) 推荐(0) 编辑
摘要: 文件读写模式 # r+ 表示读和写,光标在起始位置,读操作默认从0开始,写操作默认从末尾开始f=open('poem8','r+',encoding='utf8')print(f.tell())print(f.readline())# f.seek(0)# .write默认添加在末尾f.write( 阅读全文
posted @ 2020-03-12 07:59 wtzxxy 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 读取光标位置 f=open('poem6', 'r', encoding='utf8')# .tell显示当前光标位置,英文字母占1个位置,汉字占3个位置print(f.tell())data=f.read(10)print(data)print(f.tell())# .seek移动光标到指定位置f 阅读全文
posted @ 2020-03-12 07:57 wtzxxy 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 按行读取文件 f=open('poem5', 'r', encoding='utf8')# .readline,默认读取首行+换行符,以换行符为分隔符data=f.readline()print(data)# 执行完操作后,注意句柄停放位置print(f.readline())print(f.rea 阅读全文
posted @ 2020-03-12 07:54 wtzxxy 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 文件操作 能调用方法的一定是对象 # open+r 打开已有文件,又称为操作句柄f=open('poem1', 'r', encoding='utf8')# read默认英文、汉字皆为一个字符data=f.read(15)print(data)f.close() # open+w 清空已有文件内容, 阅读全文
posted @ 2020-03-07 11:20 wtzxxy 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 编码解码 编码(encode):将Unicode字符串(中的代码点)转换特定字符编码对应的字节串的过程和规则 解码(decode):将特定字符编码的字节串转换为对应的Unicode字符串(中的代码点)的过程和规则 encode unicode to any code decode any code 阅读全文
posted @ 2020-03-07 10:58 wtzxxy 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 三层循环 # __author:XY# date: 2020/3/7abcd = { 'A': { 'AA': { 'AAA': { 'AAAA': {}, 'AAAB': {}, 'AAAC': {}, 'AAAD': {} }, 'AAB': { 'AABA': {}, 'AABB': {}, 阅读全文
posted @ 2020-03-07 08:10 wtzxxy 阅读(443) 评论(0) 推荐(0) 编辑
摘要: 字符串操作 a="let's go"print(a)# 重复输出print(a*2)# 通过索引获取字符串中的字符,相当于切片print(a[2:])# 判断运算,关键字 in 字符串,返回 True / Falseprint('et' in a)# 格式化字符串print('%s is a tea 阅读全文
posted @ 2020-03-05 21:48 wtzxxy 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 字典 排序 dic={'name':23,'age':39,'job':48,'marriage':11}print(dic)print(sorted(dic))print(sorted(dic.keys()))print(sorted(dic.values()))print(sorted(dic. 阅读全文
posted @ 2020-03-05 08:47 wtzxxy 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 字典 {键:值,键:值} 没有位置关系,只有映射关系。 id(a) 变量a的内存地址 不可变类型:整型,字符串,元组 可变类型:列表,字典 键:不可变 值:可变 两大特点:无序,键唯一 如果存在重复键,最后一个替换之前的 创 dic={'name':'Kevin','age':39,'job':'t 阅读全文
posted @ 2020-03-05 08:43 wtzxxy 阅读(311) 评论(0) 推荐(0) 编辑