12 2019 档案
摘要:re表达式 用来匹配字符串的一个规则。 行定位符:^ 标示开始,表达结束 元字符:. \w \W \s \S \b \d ^ 限定符:?+ * {n} {n,} {n,m} 字符类:[] 排除字符:[^ ] 选择字符:| 转义字符:\ 分组:() python中使用正则表达式 需要添加 单引号
阅读全文
摘要:‘%[-][+][0][m][.n]格式化字符’%exp >>>> 3.141592653589793 >>> b'\xe4\xba\xba\xe7\x94\x9f\xe8\x8b\xa6\xe7\x9f\xad\xef\xbc\x8c\xe6\x88\x91\xe7\x94\xa8python'人
阅读全文
摘要:》》》》 {'T40': 'cj', 'T298': 'bj', 'Z158': 'sh'}{'T40': '2h', 'T298': '1h', 'Z158': '3h'}checi dizhi atimeT40 cj 2hT298 bj 1hZ158 sh 3hyou buy the checi
阅读全文
摘要:可变集合:存在唯一性,可以用于去重且无序 空集合的创建:只能用set创建 s=set() s=set([1,2,3,4,4,3,3,23434]) s.add('abc')#添加元素 s.remove('abc')#删除指定元素 w=s.pop()#随机删除一个元素,并把删除的值返回 print(s
阅读全文
摘要:key=['a','b','c','d'] value=[1,2,3,4] d=dict(zip(key,value))# zip 将多个列表或者元祖对应位置组合成zip对象#,用dict函数转换为字典,用list也可以转换为列表,用tuple转换元祖 e=tuple(zip(key,value))
阅读全文
摘要:t=(1111,222,333,444,555) for index,item in enumerate(t): print(index,item) 》》》 0 11111 2222 3333 4444 555 import random randomnumber=(random.randint(1
阅读全文
摘要:l=[] for i in range(4):#添加 行 l.append([]) #在空列表中添加空列表 for j in range(3):#添加 列 l[i].append(j) #生成二维列表 print(l) n=[[]]#空的二位列表 m=[[j for j in range(3)] f
阅读全文
摘要:判定value是否在list中 index sort和sorted 列表推导式: newlist=[Expresion for var in list if condition]
阅读全文
摘要:》》》》 查询能量来源,请输入1,2,3,4,退出输入0{'1': '生活', '2': 'walk', '3': 'bike', '4': 'netbook', '0': '退出'}1生活缴费:200g 查询能量来源,请输入1,2,3,4,退出输入0{'1': '生活', '2': 'walk',
阅读全文
摘要:with open('test3.txt','w',encoding='utf-8') as f: print('this is test3.txt',file=f) #用print 输出到文件 a=int(input('number:')) b= a if a>4 else 3 # 条件表达式简化 print(b)
阅读全文