Update python_format_output.py

This commit is contained in:
guanjihuan 2024-10-22 20:57:45 +08:00
parent 1f86f9a39f
commit f7502c90c9

View File

@ -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)
print("pi=%.2f" % value)