首页 > 解决方案 > SyntaxError: f-string: 期待 '}'

问题描述

我这里有问题。

我不知道为什么这段代码不起作用。

newline = '\n'
tasks_choosen = ['markup', 'media', 'python_api', 'script', 'style', 'vue']
print(f'{ newline }### Initializing project with the following tasks: { ' '.join(tasks_choosen) }.{ newline }')

错误:

文件“new-gulp-project.py”,第 85 行

print(f'{ newline }### 使用以下任务初始化项目:{ ' '.join(tasks_choosen) }.{ newline }')

SyntaxError: f-string: 期待 '}'

谁能帮我?

谢谢

标签: pythonsyntax-errorf-string

解决方案


因为你使用单引号两次你得到: print(f'{ newline }### Initializing project with the following tasks: { '而不是

print(f'{ newline }### Initializing project with the following tasks: { ' '.join(tasks_choosen) }.{ newline }')

在里面使用双引号:

print(f'{ newline }### Initializing project with the following tasks: { " ".join(tasks_choosen) }.{ newline }')


推荐阅读