我正在尝试将结果打印到终端,但f-string
似乎不起作用,如下所示:
print(
f'Financial Analysis\n'
'----------------------\n'
'Total Months {monthnum}\n'
'Total: ${pl}\n'
'Greatest increase in profits: {greatim} ({greati}) \n'
'Greatest decrease in profits: {greatdm} ({greatd})'
)
代码的其余部分在this repository上可用
我认为您需要在引用变量的行中使用
f''
,如下所示:在您的例子中,我还认为在字符串末尾使用
.format()
方法可能更干净,但这是个人的选择在代码中,只有第一个字符串是
f
字符串。如果你想插值,你需要把它们都变成f字符串或者,您可以使用带有多行引号的f字符串(即
''' '''
)。这可能是一个更好的解决方案:印刷品:
相关问题 更多 >
编程相关推荐