pi = 3.14159265 print(f"{pi:.5f}") # 或者使用: print(f"{'%.5f'%pi}") # 保留小数点后5位,四舍五入
输出结果
3.14159 3.14159