标签:二进制 绝对值 整理 计算 color ase 十六进制 bin 类型
数学运算:
abs : 取绝对值
round: 四舍五入取整
pow(2,3): 相当于2**3,pow(2,3,5)相当于2**3%5
divmod(9,2): 返回输出结果和余数
max([a,b]): 求最大最
min([a,b]): 求最小值
sum([a,b]): 求和
转换类型:
eval: 将字符串str当成有效的表达式来求值并返回计算结果
int: 转换为整数
float: 转换为浮点数
str: 转换为字符串
complex(3,9): 返回复数3+9j
ord("A"): 返回"A"对应的ASCII值
chr(65): 返回数字对应的ASCII中的字符
bool(): 返回对应的布尔值(python中[],(),{},0,None,0.0,‘‘都是Flase)
bin(56): 返回0b111000,二进制数
hex(56): 返回0x38,十六进制数
oct(56): 返回0o70,八进制数
list: 转换为列表
tuple: 转换为元组
dict: 转换为字典
s=slice(3,5,2)
l[s]: 将l进行切片操作,3是起始位置,5是终点位置,2是步长
all: 是否所有元素都为Ture值
any: 是否有任意元素为Ture值
type: 查看类型
isinstance(num,int): 判断num是否为int类型
num is 1: 是身份运算,根据id取判断
set: 可变集合类型
frozenset: 不可变集合
callable: 对象是否可被调用
bytes(‘hello‘,encoding=‘utf-8‘):将hello以utf-8的形式装换字节形式
dir: 可调用的函数
help: 帮助
enumerate:
for i in enumerate([‘a‘,‘b‘,‘c‘,‘d‘]): print(i)
输出结果:
(0, ‘a‘) (1, ‘b‘) (2, ‘c‘) (3, ‘d‘)
hash: 返回一个哈希值
zip: 拉链
l1=[1,2,3,4] s=‘hel‘ for i in zip(l1,s): print(i)
输出结果
(1, ‘h‘) (2, ‘e‘) (3, ‘l‘)
#1
sorted返回值是列表,默认是升序
reverse=True反向排序
l=[3,4,1,0,9,10] print(sorted(l)) print(sorted(l,reverse=True))
输出结果:
[0, 1, 3, 4, 9, 10]
[10, 9, 4, 3, 1, 0]
s=‘hello abc‘ print(sorted(s))
输出结果
[‘ ‘, ‘a‘, ‘b‘, ‘c‘, ‘e‘, ‘h‘, ‘l‘, ‘l‘, ‘o‘]
#2
map映射
标签:二进制 绝对值 整理 计算 color ase 十六进制 bin 类型
原文地址:http://www.cnblogs.com/panyouming/p/6705849.html