python - 为什么每当我尝试执行 F 字符串时我的代码都不起作用
问题描述
age = 17
age_last_year = age - 1
print(f"last year it was {age_last_year} 16.")
我知道它非常基础,这是我的第一天编码,但我很迷茫,谢谢 xd
解决方案
您忘记了"在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.
推荐阅读
- assembly - 为什么我不能打印 disk_read_error
- html - 来自 iframe 的资源不包含样式
- javascript - 将 Channel Create 语句放入 IF 语句会破坏代码
- python - 熊猫数据框中的加号等于
- haskell - 仆人选项不处理 OPTIONS 请求
- c++ - C++ 中的 Unix 网络不等待连接
- python - 服务器和客户端之间的通信问题
- swiftui - 在函数 SwiftUI 中调用新视图
- tensorflow - 使用 keras 调谐器的相关超参数
- javascript - 如何调用我从 JavaScript 中的数组中提取的函数?