进制编码相关
- bin、oct、hex (十 >> 二、八、十六,有前缀)
- int(‘11’, 2) (有前缀)或者 format(10, ‘b/o/x’)(无前缀)(二、八、十六 >> 十)
- ord(‘a’) chr(97)
- bytes(’ ', encoding=‘utf-8’) 字符串>>字节
数据结构
# 字典
dict(a='a',b='b')
dict(zip(['a','b'],[1,2]))
dict([('a',1),('b',2)])
set([1, 3, 2, 2]) {1, 2, 3}
tuple([1, 3, 2, 2]) (1, 3, 2, 2)
frozenset([1,1,3,2,3]) frozenset({1, 2, 3}) 没有add pop append等方法
a = [1,4,2,3,1]
a[slice(0, 5, 2)] [1,2,1]
算术运算
divmod(10,3) (3, 1) 元组,商和余数
pow(3,2) 幂运算
pow(3,2,4) 3、2幂运算后对4取余
round(1111.045, 2) 四舍五入,最后一位非零若是5则舍去了,很奇怪
round(1111.045, -2) 四舍五入 1100.0
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200706133926633.png)
常用函数
filter过滤器
x = [1, 2, 3, 5]
odd = filter(lambda e: e % 2, x)
for e in odd: # 找到奇数
print(e)
reduce(lambad p1,p2:p1*p2, [1, 2, 3], 4)
map(func, [1,2,3])将func函数应用到列表的每一个元素
字典生成式,列表生成式
dict.get(value, []) 不存在键value,就返回[]
# 多行输出 使用一对三重引号
print('''"Oh no!" He exclaimed.
"It's the blemange!"''')
'abcd'.find('c') 返回下标
双引号 会忽略字符串中的转义字符
单引号 就需要加 斜杠
a = [1, 3, 4, 2, 1]
sorted(a,reverse=True)
a = [{'name':'xiaoming','age':18,'gender':'male'}, {'name'