gpt4 book ai didi

python - 语法错误 : f-string: expecting '}'

转载 作者:行者123 更新时间:2023-12-03 07:59:48 28 4
gpt4 key购买 nike

我这里有问题。
我不知道为什么这段代码不起作用。

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

File "new-gulp-project.py", line 85

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

SyntaxError: f-string: expecting '}'


谁能帮我?
谢谢

最佳答案

因为您使用了两次单引号,所以您会得到: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 }')

关于python - 语法错误 : f-string: expecting '}' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63302082/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com