我尝试使用两种方法输入浮点数并输出简单的结果:
t = float(input()) print('{:.2f}'.format(1.0 - 0.95 ** t)) print('%.2f' % 1.0 - 0.95 ** t)
第一种方法有效,但第二种方法出现类型错误:
- 不支持的操作数类型:“str”和“float”。
这有什么问题吗?
python string-formatting python-3.x
python ×1
python-3.x ×1
string-formatting ×1