只为记录一些python相关的特殊写法
无穷大,无穷小,NAN
float('inf'), float('-inf'), float('nan')
判断字符的类型
isdigit(x)
isspace(x)
字符串拼接
'/'.join(['a','b','c']) # 'a/b/c'
格式转换,字符转整形
ord('a') # 97
chr(97) # 'a'
进制转换
int('101', base=2) # 5, int(string, base)
bin(5) # '0b101'
bin(5)[2:] # '101'
bin(5)[2:].zfill(8) # '00000101'
二维坐标数组[[x1,y1],[x2,y2]...]的排序,lambda表达式:按x排序
lists.sort(key=lambda x: x[0])
阶乘
from math import factorial
x = factorial(5) # 5!
排列组合
from math import comb, perm
perm(5,2) # 20
comb(5,2) # 10