This commit is contained in:
2024-10-30 21:36:01 +08:00
parent e9550aea12
commit a6308c5985

View File

@@ -38,7 +38,7 @@ print(".2f" % a/b) # 这里是错误的❌
a=10
b=3
c=a/b
print(".2f" % c) # 这样是正确的✔
print("%.2f" % c) # 这样是正确的✔
```
或者,把计算表达式用括号包起来
@@ -46,7 +46,7 @@ print(".2f" % c) # 这样是正确的✔
```py
a=10
b=3
print(".2f" % (a/b)) # 这样是正确的✔
print("%.2f" % (a/b)) # 这样是正确的✔
```
## format() 函数