SyntaxError: f-string: 期待 '}'

Ram*_*oFX 3 python syntax-error 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 }')
Run Code Online (Sandbox Code Playgroud)

错误:

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

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

SyntaxError: f-string: 期待 '}'

谁能帮我?

谢谢

v*_*ona 10

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

print(f'{ newline }### Initializing project with the following tasks: { ' '.join(tasks_choosen) }.{ newline }')
Run Code Online (Sandbox Code Playgroud)

在里面使用双引号:

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

Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

4247 次

最近记录:

5 年,4 月 前