添加“”在字符串的开头和结尾?
每当我输入像 "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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以转义内部引号:
或使用单引号
You can just escape the inner quotes:
or use single quotes
选择一个:
你不能像这样修复它
,因为那样你就会让他字符串
Muhammed 去商店说“请给我一些泡菜
和一个额外的”
结束。一般来说,您也可以使用
它,但这对于您的示例来说毫无意义。
Pick one:
You cant fix it like this
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
instead, but that would be pointless with your example.
听起来您正在将输入数据放入源代码中。不要那样做;使用文件或 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.