【发布时间】:2018-10-28 07:45:31
【问题描述】:
我的 Atom 阅读器在这里收到一条错误消息,提示第一个 print.(f"message") 正在传递错误:
File "/Users/permanentmajority/Desktop/Coding/learnpythonbook.py", line 75
print(f"Let's talk about {my_name}.")
^
SyntaxError: invalid syntax
[Finished in 0.077s]
代码:
my_name = 'Zed A. Shaw'
my_age = 35 # not a lie
my_height = 74 # inches
my_weight = 180 #lbs
my_eyes = 'Blue'
my_teeth = 'White'
my_hair = 'Brown'
print(f"Let's talk about {my_name}.")
print(f"He's {my_height} inches tall.")
print(f"He's {my_weight} pounds heavy.")
print("Actually that's not too heavy.")
print(f"He's got {my_eyes} eyes and {my_hair} hair.")
print(f"His teeth are usually {my_teeth} depending on the coffee.")
【问题讨论】:
-
您使用的是哪个 Python 版本? f-strings 是该语言相对较新的补充。
-
你至少需要python3,而不是python2
-
你能在命令提示符下输入 python 时显示正在打印的内容吗
-
在 Windows 上,您可以按 Ctrl-r,然后按
command,最后按Enter键。 -
您可以通过添加
import sys行,然后单独添加print(sys.version_info)行来查看正在使用的Python 版本。
标签: python syntax-error python-2.x f-string