python 一些常用函数
str
# C标准中空白字符有:空格(' ')、换页('\f')、换行('\n')、回车('\r')、水平制表符('\t')、垂直制表符('\v')
str.strip() # 去除两边空白符(whitespaces); str.lstrip()去除左空白; str.rstrip()去除右空白
str.replace(' ', '') # 去除全部空格
''.join(str.split()) #去除全部空白符
str.split(sep=None, maxsplits=-1) #分割字符串 sep=None默认为所有的空字符 maxsplits=-1为无限制
float格式化
https://docs.python.org/zh-cn/3/tutorial/inputoutput.html
Python 3里面,round对小数的精确度采用了四舍六入五成双的方式
num = 3.1415926
# 使用format
num1 = "{:.3f}".format(num) #3位小数
num2 = "{:.3}".format(num) #3位有效数字
# 使用%
num3 = "%.3f"%num #3位小数
https://www.cnblogs.com/fat39/p/7159881.html
用到再记