为了账号安全,请及时绑定邮箱和手机立即绑定

输出应该看起来像一个引用

输出应该看起来像一个引用

慕盖茨4494581 2023-09-26 16:13:32
我正在尝试打印引文和作者姓名。我的输出应如下所示(包括引用):阿尔伯特·爱因斯坦曾经说过:“一个从未犯过错误的人从未尝试过任何新事物。”我试过这个:quote = "A person who never made a mistake never tried anything new."message = f"Albert Einstein once said, {quote}"print(message)但我没有得到报价,我认为其余的都很好。
查看完整描述

5 回答

?
慕雪6442864

TA贡献1812条经验 获得超5个赞

你可以这样做:


>>> 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",那么单引号将不起作用。


查看完整回答
反对 回复 2023-09-26
?
白板的微信

TA贡献1883条经验 获得超3个赞

尝试这个:

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)


查看完整回答
反对 回复 2023-09-26
?
婷婷同学_

TA贡献1844条经验 获得超8个赞

尝试用


quote = '"A person who never made a mistake never tried anything new."'

message = "Albert Einstein once said, {}".format(quote)

print(message)


查看完整回答
反对 回复 2023-09-26
?
摇曳的蔷薇

TA贡献1793条经验 获得超6个赞

尝试这个


 quote = '"A person who never made a mistake never tried anything new."'

 message = f"Albert Einstein once said, {quote}"

 print(message)


查看完整回答
反对 回复 2023-09-26
?
隔江千里

TA贡献1906条经验 获得超10个赞

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

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

输出:

测试测试你好他说“很好”


查看完整回答
反对 回复 2023-09-26
  • 5 回答
  • 0 关注
  • 139 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信