添加“”在字符串的开头和结尾?

发布于 2024-12-01 04:39:37 字数 211 浏览 2 评论 0原文

每当我输入像 "Muhammed gone to the store and said "Can I have some pickles please"" 这样的字符串时,它似乎搞砸了字符串的处理方式,因为 Can I have some pickles请 变得无效。所以我想在它的两侧添加“””肯定会解决这个问题,如果有更好的解决方案,我对此持开放态度。

Whenever I feed a string like "Muhammed went to the store and said "Can I have some pickles please"" It seems to screw up how the string is handled since a Can I have some pickles please becomes invalid. So I thought adding """ at both sides of it would surely fix it, if there are any better solutions to this, I'm open to it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光暖心i 2024-12-08 04:39:37

您可以转义内部引号:

"Muhammed went to the store and said \"Can I have some pickles please\""

或使用单引号

'Muhammed went to the store and said "Can I have some pickles please"'

You can just escape the inner quotes:

"Muhammed went to the store and said \"Can I have some pickles please\""

or use single quotes

'Muhammed went to the store and said "Can I have some pickles please"'
瘫痪情歌 2024-12-08 04:39:37

选择一个:

'Muhammed went to the store and said "Can I have some pickles please"'
"Muhammed went to the store and said \"Can I have some pickles please\""

你不能像这样修复它

"""Muhammed went to the store and said "Can I have some pickles please""""

,因为那样你就会让他字符串 Muhammed 去商店说“请给我一些泡菜 和一个额外的 结束。

一般来说,您也可以使用

'''Muhammed went to the store and said "Can I have some pickles please"'''

它,但这对于您的示例来说毫无意义。

Pick one:

'Muhammed went to the store and said "Can I have some pickles please"'
"Muhammed went to the store and said \"Can I have some pickles please\""

You cant fix it like this

"""Muhammed went to the store and said "Can I have some pickles please""""

because then you would have he string Muhammed went to the store and said "Can I have some pickles please with a single extra " at the end.

In general you can also use

'''Muhammed went to the store and said "Can I have some pickles please"'''

instead, but that would be pointless with your example.

青春如此纠结 2024-12-08 04:39:37

听起来您正在将输入数据放入源代码中。不要那样做;使用文件或 sys.stdin 代替。

It sounds like you're putting input data in your source code. Don't do that; use a file or sys.stdin instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文