fstring gives SyntaxError: invalid syntax

huangapple go评论74阅读模式
英文:

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&#39;m trying to learn python using Python Crash Course 2ND EDITION so it&#39;s not the latest edition but it&#39;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 &quot;M:\My codes\Python_Crash_course\Chapter-3\greetings.py&quot;, line 2
        message = f&quot;greeting my dear friend ! {names [0].title()}&quot;.


any help would be appreciated, thanks !

(i tried rewriteng the code but i got the same result)

</details>


# 答案1
**得分**: 0

"remove &quot;.&quot; at the end of message = line and it should work" = "删除消息末尾的“。”并且它应该工作"

message = f&quot;greeting my dear friend ! {names [0].title()}&quot; = "消息 = f&quot;问候我的亲爱的朋友!{names [0].title()}&quot;"

<details>
<summary>英文:</summary>

remove &quot;.&quot; at the end of message = line and it should work

    message = f&quot;greeting my dear friend ! {names [0].title()}&quot;

</details>



huangapple
  • 本文由 发表于 2023年4月17日 03:31:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76029941.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定