输出应该看起来像一个报价

Output should look like a quotation

我正在尝试打印引文和作者姓名。我的输出应如下所示(包括引文):

Albert Einstein once said, "A person who never made a mistake never tried anything new."

我试过这个:

quote = "A person who never made a mistake never tried anything new."
message = f"Albert Einstein once said, {quote}"
print(message)

但是我没有得到报价,其他的我觉得没问题。

您需要在引号前加上反斜杠。

print("test test hello /" very good /" said him")

输出:

test test hello " very good " said him

试试

quote = '"A person who never made a mistake never tried anything new."'
message = "Albert Einstein once said, {}".format(quote)
print(message)

你可以这样做:

>>> quote = "\"A person who never made a mistake never tried anything new.\""
>>> message = f"Albert Einstein once said, {quote}"
>>> print(message)
Albert Einstein once said, "A person who never made a mistake never tried anything new."

或者您也可以这样做:

>>> quote = "A person who never made a mistake never tried anything new."
>>> message = f"Albert Einstein once said, \"{quote}\""
>>> print(message)
Albert Einstein once said, "A person who never made a mistake never tried anything new."

或者您可以用单引号将双引号引起来打印双引号。

做这样的事情:

>>> quote = '"A person who never made a mistake never tried anything new."'
>>> message = f"Albert Einstein once said, {quote}"
>>> print(message)
Albert Einstein once said, "A person who never made a mistake never tried anything new."

请注意,如果您的句子中有单引号,那么它将不起作用。例如,如果你的句子说 "A person who's never made a mistake never tried anything new",那么单引号就不行了。

试试这个

 quote = '"A person who never made a mistake never tried anything new."'
 message = f"Albert Einstein once said, {quote}"
 print(message)

试试这个:

a = "Albert Einstein once said, \"A person who never made a mistake never tried anything new.\""
print(a)

或:

a = 'Albert Einstein once said,"A person who never made a mistake never tried anything new."'
print(a)