小编alv*_*psl的帖子

为什么在 % 样式打印格式中使用算术表达式会出现类型错误?

我尝试使用两种方法输入浮点数并输出简单的结果:

t = float(input())
print('{:.2f}'.format(1.0 - 0.95 ** t))
print('%.2f' % 1.0 - 0.95 ** t)
Run Code Online (Sandbox Code Playgroud)

第一种方法有效,但第二种方法出现类型错误:

- 不支持的操作数类型:“str”和“float”。

这有什么问题吗?

python string-formatting python-3.x

1
推荐指数
1
解决办法
39
查看次数

标签 统计

python ×1

python-3.x ×1

string-formatting ×1