摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
统计单词次数 作为字典存储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... 阅读全文
摘要:
content = {"name":"wd","pc":{"phone":111111,"age":18},"woniu":["122222",18]} 增 content['kk'] = 'test' 删 content.pop("kk") 注意 列表有序,可以直接pop() 改 content[ 阅读全文
摘要:
格式 [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 阅读全文
摘要:
转自https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00138683221577998e407bb309542d9b6a68d9276bc3dbe000 在程序运行的过程中,所有的 阅读全文
摘要:
获得当前目录路径 :os.getcwd() 返回指定目录下的所有文件和目录名:os.listdir() 删除一个文件:os.remove(filename) 删除多个空目录 :os.removefirs(r:"d:\python") 检查给出的路径是否是一个文件:os.path.isfile(fil 阅读全文
摘要:
存主机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 阅读全文
摘要:
1. 字符串转列表 str1 = "hi hello world" print(str1.split(" "))输出:['hi', 'hello', 'world'] 2.字典变换为 list dict.items() 3. 列表转字符串 l = ["hi","hello","world"] pri 阅读全文
摘要:
#查 #查 #增 #增 #改 #改 #删 #删 阅读全文