风-fmgao

导航

2018年5月16日

省市县_me

摘要: # question 11import astfrom functools import reducedef file_read(): with open('D:\\pytharm\\jichuyufa\\day2\\pro_cty_con.txt', 'r', encoding='utf8') a 阅读全文

posted @ 2018-05-16 17:22 风-fmgao 阅读(82) 评论(0) 推荐(0) 编辑

python读取文件中的字典

摘要: import astdef file_read(): with open('D:\\pytharm\\jichuyufa\\day2\\pro_cty_con.txt', 'r', encoding='utf8') as f: san_dic = ast.literal_eval(f.read()) 阅读全文

posted @ 2018-05-16 14:24 风-fmgao 阅读(1764) 评论(0) 推荐(0) 编辑

省市县

摘要: #!/usr/bin/python3# -*- coding: utf-8 -*-# @Time : 2018/5/16 10:43# @File : shengshi.pydic = { "河北":{ "石家庄" :["鹿泉","藁城","元氏"], "邯郸" : ["永年","涉县","磁县"] 阅读全文

posted @ 2018-05-16 11:22 风-fmgao 阅读(164) 评论(0) 推荐(0) 编辑

布尔值运算&集合

摘要: 示例:返回booleanli = [] li = {} li = () if not li: print(1) radiansdict.has_key(key) #如果键在字典dict里返回true,否则返回false 示例所有的数据类型都自带布尔值,数据只有在0,None和空的时候为Falsepr 阅读全文

posted @ 2018-05-16 10:33 风-fmgao 阅读(872) 评论(0) 推荐(0) 编辑

商品列表,添加,显示

摘要: def file_read(): with open('D:\\pytharm\\jichuyufa\\day2\\shop.txt', 'r', encoding='utf8') as f: for i1 in f.readlines(): li1 = i1.split(',') print(li 阅读全文

posted @ 2018-05-16 10:07 风-fmgao 阅读(321) 评论(0) 推荐(0) 编辑

python 文件读写模式r,r+,w,w+,a,a+的区别(附代码示例)

摘要: 模式 可做操作 若文件不存在 是否覆盖r 只能读 报错 -r+ 可读可写 报错 是w 只能写 创建 是w+ 可读可写 创建 是a 只能写 创建 否,追加写a+ 可读可写 创建 否,追加写1.只读模式(r)一个存在的文件:def file_operation(): with open('/wzd/te 阅读全文

posted @ 2018-05-16 09:52 风-fmgao 阅读(2030) 评论(0) 推荐(0) 编辑

2018年5月15日

Python 列表(List) 的三种遍历(序号和值)方法

摘要: #!/usr/bin/env python# -*- coding: utf-8 -*-if __name__ == '__main__': list = ['html', 'js', 'css', 'python'] # 方法1 print '遍历列表方法1:' for i in list: pr 阅读全文

posted @ 2018-05-15 15:37 风-fmgao 阅读(1832) 评论(0) 推荐(0) 编辑

python 列表转为字典的两个小方法

摘要: 1、现在有两个列表,list1 = ['key1','key2','key3']和list2 = ['1','2','3'],把他们转为这样的字典:{'key1':'1','key2':'2','key3':'3'}list1 = ['key1','key2','key3']list2 = ['1' 阅读全文

posted @ 2018-05-15 15:15 风-fmgao 阅读(4061) 评论(0) 推荐(0) 编辑

python输出格式化及函数format

摘要: 格式 描述%% 百分号标记%c 字符及其ASCII码%s 字符串%d 有符号整数(十进制)%u 无符号整数(十进制)%o 无符号整数(八进制)%x 无符号整数(十六进制)%X 无符号整数(十六进制大写字符)%e 浮点数字(科学计数法)%E 浮点数字(科学计数法,用E代替e)%f 浮点数字(用小数点符 阅读全文

posted @ 2018-05-15 14:34 风-fmgao 阅读(349) 评论(0) 推荐(0) 编辑

re.sub()

摘要: python resub方法re.sub(pattern, repl, string, count=0, flags=0)re是regular expression的所写,表示正则表达式sub是substitute的所写,表示替换;re.sub是个正则表达式方面的函数,用来实现通过正则表达式,实现比 阅读全文

posted @ 2018-05-15 11:08 风-fmgao 阅读(455) 评论(0) 推荐(0) 编辑