我收到此错误:
AttributeError: 'float' object has no attribute '3f'
我不明白我为什么会得到它,我直接从“应用文本分析”一书中遵循示例
python中的代码块是:
total = sum(words.values())
for gender, count in words.items():
pcent = (count / total) * 100
nsents = sents[gender]
print(
"{0.3f}% {} ({} sentences)".format(pcent, gender, nsents)
)
我清楚地看到pcent会返回一个浮点数,为什么作者试图申请 .3f 我错过了什么?