Set 集合 set - unordered collections of unique elements 创建一个set/一个空set # create a new set set1 = {1,2,3} print(type(set1)) # result => <class 'set> set2 = set() print(type(set2)) # create an empty set, result => <class 'set'> # as the obje…
一.三元运算 三元运算又称三目运算,是对简单的条件语句的简写,如: 简单条件处理: 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…
一.三目(元)运算符 定义:就是 if...else...语法糖前提:简化if...else...结构,且两个分支有且只有一条语句注:三元运算符的结果不一定要与条件直接性关系 cmd = input('cmd: ') print('可以转化为数字') if cmd.isdigit() else print('不可以转化为数字') a = 20 b = 30 res = a if a > b else b # 求大值 print(res) res = 'b为小值' if a >…
一.字符串格式化 Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This PEP proposes a new system for built-in string formatting operations, intended as a replacement for the existing '%' string formatting operat…
· 三元运算又称三目运算,是对简单条件语句的简写,如: 简单条件语句: if 条件成立: val = 1 else: val = 2 改成三元运算: val = 1 if 条件成立 else 2 >>> a = 3 >>> b = 5 >>> val = a if a>b else b >>> val 5…