SyntaxError: f-string: expecting '}'
SyntaxError: f-string: expecting '}'
我这里有问题。
我不知道为什么这段代码不起作用。
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 和 ' ' (single-quotes) 使用 ' ' (single-quotes) 时感到困惑,所以它对 f-string 实际结束的位置感到困惑。在 .join() 之前用“”替换“”,它应该可以工作:)
我这里有问题。
我不知道为什么这段代码不起作用。
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 和 ' ' (single-quotes) 使用 ' ' (single-quotes) 时感到困惑,所以它对 f-string 实际结束的位置感到困惑。在 .join() 之前用“”替换“”,它应该可以工作:)