英文:
fstring gives SyntaxError: invalid syntax
问题
I'm here to help with the translation. Here's the translated code part:
我正在尝试使用《Python程序崩溃课程第二版》来学习Python,所以它不是最新版,但我猜它使用的是Python 3.6。我的Python版本是3.10.11
这是我的代码:
names = ['sepehr', 'farzad', 'mahan', 'arting', 'saeed']
message = f"问候我的亲爱的朋友!{names[0].title()}"
print(message)
当我尝试在命令提示符中运行这段代码时,我得到了这个错误:
File "M:\My codes\Python_Crash_course\Chapter-3\greetings.py", line 2
message = f"问候我的亲爱的朋友!{names[0].title()}"
希望这可以帮助您,谢谢!(我尝试重新编写代码,但结果相同)
<details>
<summary>英文:</summary>
I'm trying to learn python using Python Crash Course 2ND EDITION so it's not the latest edition but it's using Python 3.6 i guess. my python version is 3.10.11
this is my code:
names = ['sepehr', 'farzad', 'mahan', 'arting', 'saeed']
message = f"greeting my dear friend ! {names [0].title()}".
print (message)
when i try to run the code in cmd i get this:
File "M:\My codes\Python_Crash_course\Chapter-3\greetings.py", line 2
message = f"greeting my dear friend ! {names [0].title()}".
any help would be appreciated, thanks !
(i tried rewriteng the code but i got the same result)
</details>
# 答案1
**得分**: 0
"remove "." at the end of message = line and it should work" = "删除消息末尾的“。”并且它应该工作"
message = f"greeting my dear friend ! {names [0].title()}" = "消息 = f"问候我的亲爱的朋友!{names [0].title()}""
<details>
<summary>英文:</summary>
remove "." at the end of message = line and it should work
message = f"greeting my dear friend ! {names [0].title()}"
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论