![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
q328428003
这个作者很懒,什么都没留下…
展开
-
python文件IO及其相关问题
前天用python做项目,将字典存入文件,以及读取文件中的字典。遇到的几个问题:1.打开文件的时候为什么要用with open('file' , 'r') as f:2.字典在文件中的读取与存入方法在网上找到了答案。1.关于 with ... as ...其实它的正确写法应该是try: f = open('xxx')except: print 'fail to open' ...转载 2018-03-09 23:40:32 · 159 阅读 · 0 评论 -
python 的 is 与 == 区别
输入如下代码>>> b = [0, 1]>>> c = b[:]>>> d = b>>> print(b is c)False>>> print(b is d)True为什么会有如上结果呢?"is" 比较的是两个实例对象是不是完全相同,它们是不是同一个对象,占用的内存地址原创 2018-03-11 11:02:56 · 161 阅读 · 0 评论 -
python 字典修改key的方法
环境python3,今天在温习字典的时候想起来,如果我字典想要修改key而不改动value呢?>>> a = {"yuntian":"zero", "Alex":"Li"}我想要把"yuntian"由小写改为大写,应该怎样操作呢?a.["Yuntian"] = a.["yuntian"]a.pop("yuntian&原创 2018-03-12 13:34:03 · 18751 阅读 · 2 评论