感觉已经荒废了好久了。。。。。
1.% 百分号格式化
-%s 传所有值
-%d 传整型
-%.2f 传浮点数
-%% 打印%
-%() 传字典键值
- + 右对齐
- - 左对齐
- \033[43:1m \033[0m 颜色
- width 占有宽度
-sep = ':' 字符串中间加:
2.format字符串格式化
-dfg = 'i am {},age{}'.format{'wds',18}
-dfg = 'i am {1},age{0}'.format{'wds',18}
-dfg = 'i am {name},age{age}'.format{**'name':'wds','age':18}
-dfg = 'i am {name},age{age}'.format{'name'='wds','age'=18}
-dfg = 'i am {:s},age{:d}'.format{'wds',18}
-dfg = 'i am {:s},age{:d}'.format{*['wds',18]}
3.函数
-def test(x):
x += 1
return x
-global() 全局变量
-nonlocal() 上一级变量
-作用域
-匿名函数
lambda x:x+1
def test(x):
return x+1
-map函数 依次处理原列表每一个元素
-reduce函数 把值合并起来
-filter函数 把值进行筛选
-内置函数
-abs() 绝对值
-all() 布尔运算,有假就假
-any() 布尔运算,有真为真
-bin() 十进制转二进制
-hex() 10->16
-oct() 10->8
-bool() 空,none,0
-bytes() 字符串转字节 encoding 编码 decode 解码
-chr() ascll码
-dir() 对象的方法
-divmod() 分页
-eval() 计算字符串中的数字 提取字典
-hash() 可hash的数据类型即不可变数据类型
-help()
-global() 全局变量
-locals() 局部
-zip() 拉链
-max() 最大值
-min() 最小值