摘要: print "hello %s %s" % ('wd','pc') c风格 print "hello {1} {0}".format("wd",pc') c#风格 可以定义字符串的顺序 list = ['hello','1','7'] '%s %d-%d' % ('hello',7,1) 结果 'hello 7-1' '%s,%s:%s' % (lis... 阅读全文
posted @ 2017-11-01 21:26 一只宅男的自我修养 阅读(129) 评论(0) 推荐(0) 编辑
摘要: dict1 = {1:2,3:4,6:7,9:10} print dict((v,k) for k,v in dict.items()) 结果 {2:1.4:3,10:9,7:6} res = [{'id':1,'name':'wd','age':'18'},{'id':2,'name':'pc','age':'20'}] dict((str(x['id']),x['name'])f... 阅读全文
posted @ 2017-10-30 21:39 一只宅男的自我修养 阅读(349) 评论(0) 推荐(0) 编辑
摘要: 统计单词次数 作为字典存储cotent = "who have an apple apple is free free is money you know" result = {} for s in content.split(""): if s in result: result[s] + =1 else: result[s] = 1 print... 阅读全文
posted @ 2017-10-29 21:49 一只宅男的自我修养 阅读(343) 评论(0) 推荐(0) 编辑
摘要: content = {"name":"wd","pc":{"phone":111111,"age":18},"woniu":["122222",18]} 增 content['kk'] = 'test' 删 content.pop("kk") 注意 列表有序,可以直接pop() 改 content[ 阅读全文
posted @ 2017-10-28 15:36 一只宅男的自我修养 阅读(3004) 评论(0) 推荐(0) 编辑
摘要: 格式 [x for x in 内容] [x for x in 内容 if 条件] 例子 单循环列表生成式 [x for x in 'abcd'] ['a','b','c','d'] list = [10,11,12,13] [x for x in list if x >10] 输出 11,12,13 阅读全文
posted @ 2017-10-27 22:10 一只宅男的自我修养 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 转自https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00138683221577998e407bb309542d9b6a68d9276bc3dbe000 在程序运行的过程中,所有的 阅读全文
posted @ 2017-10-27 08:36 一只宅男的自我修养 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 获得当前目录路径 :os.getcwd() 返回指定目录下的所有文件和目录名:os.listdir() 删除一个文件:os.remove(filename) 删除多个空目录 :os.removefirs(r:"d:\python") 检查给出的路径是否是一个文件:os.path.isfile(fil 阅读全文
posted @ 2017-10-27 08:28 一只宅男的自我修养 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 存主机ip到列表 host_list=[] netip='192.168.1' for hostip in range(1,254): ip = netip +str(hostip) host_list.append(ip) hostlist 列表遍历 shoplist = [apple,mango 阅读全文
posted @ 2017-10-26 22:05 一只宅男的自我修养 阅读(308) 评论(0) 推荐(0) 编辑
摘要: 1. 字符串转列表 str1 = "hi hello world" print(str1.split(" "))输出:['hi', 'hello', 'world'] 2.字典变换为 list dict.items() 3. 列表转字符串 l = ["hi","hello","world"] pri 阅读全文
posted @ 2017-10-26 22:02 一只宅男的自我修养 阅读(179) 评论(0) 推荐(0) 编辑
摘要: #查 #查 #增 #增 #改 #改 #删 #删 阅读全文
posted @ 2017-10-26 21:45 一只宅男的自我修养 阅读(297) 评论(0) 推荐(0) 编辑