|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
【文件存储】
打开文件 f = open("D:\\Python\\record.txt")
得到对象 f ,<_io.TextIOWrapper name='D:\\Python\\record.txt'
mode='r' encoding='cp936'>
读取文件 f.read() 文件读取位置会有一个指针作为标识
关于指针 f.read() 读取全部文件,指针在末尾 f.read()--‘空’
f.read(5) 读取 5 个字符
f.tell() 得到指针位置
f.seek(45,0) 移动指针位置到‘’
f.readline() 一行
写入文件 f = open("D:\\test.txt","w") 在写入模式创建一个 test 文件
f.write("我爱鱼C工作室") 写入
f.close() 将缓存中的文件『提交』并关闭
路径,文件,读写---------------------
【字典】
dict1 = {'key':'value'} --------> dict[key]
dict1 = dict((('k1',v1),('k2',v2),('k3',v3))) ----> 映射关系
dict1 = dict( k1 = v1,k2 = v2 ) 『keyword can't be an expression』
dict1['k1'] = 'value'
键存在,就更改值,不存在,就追加
-------------------------------------
dict1 = {}
dict1.fromkeys((1,2,,3),'number') 创建字典 值单一(只是创建,不存在覆盖)
dict1.keys(),dict1.values() , dict1.items()----------一些方法
dict.get(key) ----- 得到键,避免值错误
dict.get(key,'木有')
key in dict1 ----- key是否存在
dict1.clear() ------ 清空字典
a.copy() ------- 赋值与拷贝id值不一样
a.pop(2) a.popitem() 随机,弹出来
a.setdefault(5,'小白') 增加字典项
a.update(b) 更新字典 |
|