【发布时间】:2023-01-22 11:36:08
【问题描述】:
我最近通过观看CS50课程开始学习编程。我目前正在介绍 Python。一切都是我按照那个视频课程完成的。通过编写简单的代码,我遇到了一个与我的讲师不同的问题。
这里是:
answer = input("What's your name?")
print(f"hello, {answer}")
我遇到的问题:
File "hi.py", line 2
print(f"hello, {answer}")
^
SyntaxError: invalid syntax
我将真诚地感谢您的回答!
【问题讨论】:
-
请格式化代码 - 选择它并键入
ctrl-k。 .. Formatting help... Formatting sandbox -
您使用的是什么版本的 Python?它可能是一个早于 f-strings 的版本,如果没记错的话,f-strings 是在 Python 3.6 中引入的。
-
我正在使用 Python 2.7.16
-
Python 2 已经停产两年多了。我强烈建议您安装 Python 3。当前版本是 Python 3.10。
-
感谢您的支持,克里斯!
标签: python visual-studio