【问题标题】:SyntaxError: f-string: expecting '}' in pythonSyntaxError: f-string: 在 python 中期待 '}'
【发布时间】:2022-01-24 04:11:40
【问题描述】:
def get_descriptive_name(self):
    long_name = f"{self.year} {self.make = make} {self.model = model}"
    return long_name.title()
    print(long_name)

我不知道我的代码发生了什么。任何人都可以帮助我吗?我刚开始学习 python 中的类,我发现了这个错误语法。如果你能帮助我,我真的很高兴。谢谢!!!

【问题讨论】:

    标签: python class


    【解决方案1】:

    您不能在 f'' 字符串中包含 =。我想这就是你的本意-

    self.make,self.model=make,model
    long_name = f"{self.year} {self.make} {self.model}"
    

    【讨论】:

    • 是的,谢谢。我只是从 init 复制它,我忘了删除 =
    猜你喜欢
    • 2020-11-27
    • 1970-01-01
    • 1970-01-01
    • 2019-10-29
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    相关资源
    最近更新 更多