为什么打印格式时会收到语法错误

Why do I receive syntax error while printing format

Person = { 'name' : " Jehn", ' age':23}
Sentence= f' My name is {person ['name']} and i am {person['age']} years old.'

您可以更改格式字符串中的引号类型,使其用双引号括起来,如下所示:

person = { 'name' : " Jehn", 'age':23} 
sentence = f" My name is {person ['name']} and i am {person['age']} years old."

请注意,' age' 中还有 space,这很容易被忽略。此外,我将变量更改为全部小写字母,以更加 Pythonic 和一致。