From f7502c90c95fc4bd87360905134449814ce59b56 Mon Sep 17 00:00:00 2001 From: guanjihuan Date: Tue, 22 Oct 2024 20:57:45 +0800 Subject: [PATCH] Update python_format_output.py --- .../python_format_output.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/2024.10.21_python_format_output/python_format_output.py b/2024.10.21_python_format_output/python_format_output.py index 5926515..1996ce5 100644 --- a/2024.10.21_python_format_output/python_format_output.py +++ b/2024.10.21_python_format_output/python_format_output.py @@ -1,11 +1,11 @@ -# 小数的格式化输出(浮点) value = 3.141592653589793 + +# 非格式化输出 +print("pi=", value) # 直接输出 +print("pi="+str(value)) # 转成字符串输出 +print(f"pi={value}") # 使用 f 形式 + +# 格式化输出 print(f"pi={value:.2f}") print("pi={:.2f}".format(value)) -print("pi=%.2f" % value) - -# 整数的格式化输出 -value = 13 -print(f"a={value:5d}") -print("a={:5d}".format(value)) -print("a=%5d" % value) \ No newline at end of file +print("pi=%.2f" % value) \ No newline at end of file