基本代码演示:
s = 'π is {}'.format(3.1415) print(s)
保留两位小数代码操作:
s = 'π is {:.2f}'.format(3.1415926) print(s)
输出结果:
3.14
上一篇:python中format函数怎么与字符串拼接
下一篇:python中random.randint函数的用法