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