无法使用Repl.it正确f弦

问题描述 投票:-2回答:1

我尝试使用f-string格式化字符串,但它总是会说语法错误或输入错误。

def say_hello(name, feeling):
    print(f "Hello {name} {feeling}")

say_hello('Tony', 'Grumpy')

Code and error screenshot.

我在做什么错?

python read-eval-print-loop f-string
1个回答
0
投票

只是您的print语句的语法无效

print(f"Hello {name} {feeling}")

代替

print(f "Hello {name} {feeling}")
© www.soinside.com 2019 - 2024. All rights reserved.