如何在字符串旁边打印变量的值,该字符串的值是整数?

时间:2019-09-27 15:28:06

标签: python python-3.x python-3.7

您好,Python编码人员今天过得怎么样?我有一个问题...

如何在字符串旁边打印变量的值,该字符串的值是整数?

我知道在Python 3中打印变量的一种方法。

print(variable)

我看到的另一种方式是:

print("Some string here: ", variable)

我在我的代码上尝试了它,并以某种方式工作了,但不是我想要的...我的意思是我要打印的代码行是:

print("Dogs Years: ", human_years)

,此行的输出为:

('Dogs Years: ', 19.5)

但是预期的输出是:

Dogs Years: 19.5

如何实现?

2 个答案:

答案 0 :(得分:1)

尝试使用f' prefix

print(f'Dogs Years: {human_years}')

答案 1 :(得分:0)

print('Dog years: {}'.format(human_years))