一.三元运算 三元运算又称三目运算,是对简单的条件语句的简写,如: 简单条件处理: if 条件成立: val = 1 else: val = 2 改成三元运算 val = 1 if 条件成立 else 2 二.智能检测文件编码 用第三方模块chardet 首先要安装chardet模块 ,用pip命令进行安装 chardet的用法 import chardet f = open("staff_table.txt","rb") data =f.read() f.clos…
Python列表解析 l = ["egg%s" %i for i in range(100) if i > 50] print(l) l= [1,2,3,4] s = 'hello' l1 = [(num,s1) for num in l for s1 in s] print(l1) l1 =[] for num in l: for s1 in s: t = (num,s1) l1.append(t) print(l1) import os g = os.walk('D:\\te…