首页 > 解决方案 > 为什么每当我尝试执行 F 字符串时我的代码都不起作用

问题描述

age = 17
age_last_year = age - 1
print(f"last year it was {age_last_year} 16.")

我知道它非常基础,这是我的第一天编码,但我很迷茫,谢谢 xd

标签: python

解决方案


您忘记了"print语句的末尾。

age = 17
age_last_year = age - 1
print(f"last year it was {age_last_year}.")

输出

>>> last year it was 16.

或者你可以使用格式

age = 17
age_last_year = age - 1
print("last year it was {}.".format(age_last_year))

输出

>>> last year it was 16.


推荐阅读