当句子有引号或引号时如何制作字符串?Python

例如,我有一个句子,例如:

Jamie's car broke "down" in the middle of the street

如何在不手动删除引号和引号的情况下将其转换为字符串,例如:

'Jamies car broke down in the middle of the street'

任何帮助表示赞赏!谢谢,


慕仙森
浏览 148回答 3
3回答

摇曳的蔷薇

replace()一个接一个地使用:s = """Jamie's car broke "down" in the middle of the street"""print(s.replace('\'', '').replace('"', ''))# Jamies car broke down in the middle of the street

翻阅古今

试试这个:oldstr = """Jamie's car broke "down" in the middle of the street""" #Your problem stringnewstr = oldstr.replace('\'', '').replace('"', '')) #New string using replace()print(newstr) #print result这将返回:Jamies car broke down in the middle of the street
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python