Python: SyntaxError: f-string: expecting '}'
这段代码:
tasks = ['markup', 'media', 'script'] print(f'Initializing project with the following tasks:{ ' '.join(tasks) }')
报错:
File "project.py", line 85 print(f'Initializing project with the following tasks:{ ' '.join(tasks) }') SyntaxError: f-string: expecting '}'
2. 相关原因:
因为f-string使用了两次单引号。
3. 解决办法:
单引号里面使用双引号。
f'Initializing project with the following tasks:{ " ".join(tasks) }'